Skip to content

Commit

Permalink
Merge pull request #27 from nocaway/master
Browse files Browse the repository at this point in the history
Initial YSQL document for release 1.2
  • Loading branch information
nocaway authored Mar 8, 2019
2 parents e82ee6e + ee1f37b commit fb344c6
Show file tree
Hide file tree
Showing 82 changed files with 6,213 additions and 2,202 deletions.
95 changes: 16 additions & 79 deletions docs/content/latest/api/ysql/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@ description: YugaByte Structured Query Language (YSQL) [Beta]
summary: Reference for the YSQL API
image: /images/section_icons/api/pgsql.png
beta: /faq/product/#what-is-the-definition-of-the-beta-feature-tag
aliases:
- /latest/api/postgresql/
- /latest/api/ysql/
menu:
latest:
identifier: api-postgresql
identifier: api-ysql
parent: api
weight: 1300
weight: 3000
aliases:
- /latest/api/ysql/
isTocNested: true
showAsideToc: true
---

## Introduction
YSQL is a distributed SQL API compatible with PostgreSQL. It supports the following features.
YSQL - YugaByte Structured Query Language - is a distributed SQL API compatible with PostgreSQL. Similar to PostgreSQL, YSQL has several components being constructed by a number of elements.

- Data definition language (DDL) statements.
- Data manipulation language (DML) statements.
- Builtin functions and Expression operators.
- Primitive user-defined datatypes.
The main components of YSQL are Data definition language (DDL), Data manipulation language (DML), and Data control language (DCL). Several other components are also provided for different purposes such as system control, transaction control, and performance tuning.

A number of elements are used to construct the languages in YSQL such as datatypes, database objects, names and qualifiers, expressions, and comments.

## Example
The following example illustrates how to use `psql` to connect to YugaByte DB's PostgreSQL API.
It assumes you have [installed YugaByte](../../quick-start/install/) and started a [PostgreSQL-enabled cluster](../../quick-start/test-postgresql/).
The following example illustrates how to use `psql` to connect to YugaByte DB's PostgreSQL-compatible API. It assumes you have [installed YugaByte](../../quick-start/install/) and started a [PostgreSQL-enabled cluster](../../quick-start/test-postgresql/).

```sh
$ bin/psql -p 5433 -U postgres
Expand Down Expand Up @@ -59,73 +56,13 @@ postgres=# select * from sample ORDER BY id DESC;
```
The examples given in the rest of this section assume the cluster is running and `psql` is connected to it as described above.

## DDL Statements
Data definition language (DDL) statements are instructions for the following database operations.

- Create and drop database objects.

Statement | Description |
----------|-------------|
[`CREATE DATABASE`](ddl_create_database) | Create a new database |
[`CREATE TABLE`](ddl_create_table) | Create a new table |
[`DROP DATABASE`](ddl_drop_database) | Delete a database and associated objects |
[`DROP TABLE`](ddl_drop_table) | Delete a table from a database |
[`CREATE VIEW`](ddl_create_view) | Create a new view |
[`CREATE USER`](permissions) | Create a new user/role |
[`GRANT`](permissions) | Grant permissions|
[`REVOKE`](permissions) | Revoke permissions |

## DML Statements
Data manipulation language (DML) statements read from and write to the existing database objects. Currently, YugaByte DB implicitly commits any updates by DML statements.

Statement | Description |
----------|-------------|
[`INSERT`](dml_insert) | Insert rows into a table |
[`SELECT`](dml_select) | Select rows from a table |
[`UPDATE`] | In progress. Update rows in a table |
[`DELETE`] | In progress. Delete rows from a table |

## Transactions
Statement | Description |
----------|-------------|
[`ABORT` | `ROLLBACK`](transactions) | Rollback a transaction |
[`BEGIN`](transactions) | Start a transaction |
[`END` | `COMMIT`](transactions) | Commit a transaction |

## Sequences
Statement | Description |
----------|------------|
[`CREATE SEQUENCE`](create_sequence) | Create a new sequence |
[`DROP SEQUENCE`](drop_sequence) | Drop a sequence |
[`nextval(sequence)`](nextval_sequence) | Get the next value in the sequence
[`currval(sequence)`](currval_sequence) | Get the last value returned by the most recent nextval call for the specified sequence
[`lastval()`](lastval_sequence) | Get the last value returned by the most recent nextval call for any sequence

- `ALTER SEQUENCE` and `setval()` are not supported yet.

## Other SQL Statements

Statement | Description |
----------|-------------|
[`EXECUTE`](prepare_execute) | Insert rows into a table |
[`EXPLAIN`](explain) | Insert rows into a table |
[`PREPARE`](prepare_execute) | Select rows from a table |
[`SET`](transactions) | Select rows from a table |
[`SHOW`](transactions) | Select rows from a table |
## References

## Expressions
PostgreSQL builtin functions and operators are supported.
User-defined functions are currently in progress.
### Commands
All suppoted commands are listed in the [Commands](commands/) section.

## Data Types
The following table lists all supported primitive types.
### Data Types
All PostgresSQL-compatible types are supported although not all of them can be used for columns in PRIMARY KEY yet. All suppoted types are listed in the [Data Types](datatypes/) section.

Primitive Type | Allowed in Key | Type Parameters | Description |
---------------|----------------|-----------------|-------------|
[`BIGINT`](type_int) | Yes | - | 64-bit signed integer |
[`DOUBLE PRECISION`](type_number) | Yes | - | 64-bit, inexact, floating-point number |
[`FLOAT`](type_number) | Yes | - | 64-bit, inexact, floating-point number |
[`REAL`](type_number) | Yes | - | 32-bit, inexact, floating-point number |
[`INT` | `INTEGER`](type_int) | Yes | - | 32-bit signed integer |
[`SMALLINT`](type_int) | Yes | - | 16-bit signed integer |
[`TEXT` | `VARCHAR`](type_text) | Yes | - | Variable-size string of Unicode characters |
### Expressions
All PostgreSQL-compatible builtin functions and operators are supported. User-defined functions are currently in progress. All suppoted expressions are listed in the [Expressions](exprs/) section.
57 changes: 57 additions & 0 deletions docs/content/latest/api/ysql/commands/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: Commands
description: Overview on YSQL Commands
summary: Overview on YSQL Commands
image: /images/section_icons/api/pgsql.png
menu:
latest:
identifier: api-ysql-commands
parent: api-ysql
weight: 4100
aliases:
- /latest/api/ysql/commands/
isTocNested: true
showAsideToc: true
---

The following table lists all SQL commands that are supported by YugaByte Database.

| Statement | Description |
|-----------|-------------|
| [`ABORT`](txn_abort) | Rollback a transaction |
| [`ALTER DATABASE`](ddl_alter_db) | Change database definition |
| [`ALTER TABLE`](ddl_alter_table) | Change table definition |
| [`BEGIN TRANSACTION`](txn_begin) | Start a transaction |
| [`COMMIT`](txn_commit) | Commit a transaction |
| [`COPY`](cmd_copy) | Copy data between tables and files |
| [`CREATE DATABASE`](ddl_create_database) | Create a new database |
| [`CREATE INDEX`](ddl_create_index) | Create a new index |
| [`CREATE SCHEMA`](ddl_create_schema) | Create a new schema (namespace) |
| [`CREATE SEQUENCE`](ddl_create_sequence) | Create a new sequence generator |
| [`CREATE TABLE`](ddl_create_table) | Create a new table |
| [`CREATE TABLE AS`](ddl_create_table_as) | Create a new table |
| [`CREATE USER`](dcl_create_user) | Create a new user (role) |
| [`CREATE VIEW`](ddl_create_view) | Create a new view |
| [`DEALLOCATE`](txn_deallocate) | Deallocate a prepared statement |
| [`DELETE`](dml_delete) | Delete rows from a table |
| [`DROP DATABASE`](ddl_drop_database) | Delete a database and associated objects |
| [`DROP SEQUENCE`](ddl_drop_sequence) | Delete a sequence generator |
| [`DROP TABLE`](ddl_drop_table) | Delete a table from a database |
| [`END TRANSACTION`](txn_end) | Commit a transaction |
| [`EXECUTE`](perf_execute) | Insert rows into a table |
| [`EXPLAIN`](perf_explain) | Insert rows into a table |
| [`GRANT`](dcl_grant) | Grant permissions |
| [`INSERT`](dml_insert) | Insert rows into a table |
| [`LOCK`](txn_lock) | Lock a table |
| [`PREPARE`](perf_prepare) | Select rows from a table |
| [`RESET`](cmd_reset) | Reset a variable to factory settings |
| [`REVOKE`](dcl_revoke) | Revoke permissions |
| [`ROLLBACK`](txn_rollback) | Rollback a transaction |
| [`SELECT`](dml_select) | Select rows from a table |
| [`SET`](cmd_set) | Set a system, session, or transactional parameter |
| [`SET CONSTRAINTS`](cmd_set_constraints) | Set constraints on current transaction|
| [`SET TRANSACTION`](txn_set) | Set transaction behaviors |
| [`SHOW`](cmd_show) | Show value of a system, session, or transactional parameter |
| [`SHOW TRANSACTION`](txn_show) | Show properties of a transaction |
| [`TRUNCATE`](ddl_truncate) | Clear all rows from a table |
| [`UPDATE`](dml_update) | Update rows in a table |
Loading

0 comments on commit fb344c6

Please sign in to comment.