Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/main/sphinx/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Refer to the following sections for further details:
```{toctree}
:maxdepth: 1

sql/alter-branch
sql/alter-materialized-view
sql/alter-schema
sql/alter-table
Expand All @@ -19,6 +20,7 @@ sql/analyze
sql/call
sql/comment
sql/commit
sql/create-branch
sql/create-catalog
sql/create-function
sql/create-materialized-view
Expand All @@ -33,6 +35,7 @@ sql/deny
sql/describe
sql/describe-input
sql/describe-output
sql/drop-branch
sql/drop-catalog
sql/drop-function
sql/drop-materialized-view
Expand Down Expand Up @@ -62,6 +65,7 @@ sql/set-role
sql/set-session
sql/set-session-authorization
sql/set-time-zone
sql/show-branches
sql/show-catalogs
sql/show-columns
sql/show-create-function
Expand Down
26 changes: 26 additions & 0 deletions docs/src/main/sphinx/sql/alter-branch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ALTER BRANCH

## Synopsis

```text
ALTER BRANCH source_branch IN TABLE table_name FAST FORWARD TO target_branch
```

## Description

Fast-forward the current snapshot of one branch to the latest snapshot of
another.

## Examples

Fast-forward the `main` branch to the head of `audit` branch in the `orders`
table:

```sql
ALTER BRANCH main IN TABLE orders FAST FORWARD TO audit
```

## See also

- {doc}`create-branch`
- {doc}`drop-branch`
46 changes: 46 additions & 0 deletions docs/src/main/sphinx/sql/create-branch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# CREATE BRANCH

## Synopsis

```text
CREATE [ OR REPLACE ] BRANCH [ IF NOT EXISTS ] branch_name
[ WITH ( property_name = expression [, ...] ) ]
IN TABLE table_name
[ FROM source_branch ]
```

## Description

Create a branch.

The optional `OR REPLACE` clause causes an existing branch with the
specified name to be replaced with the new branch definition. Support
for branch replacement varies across connectors. Refer to the
connector documentation for details.

The optional `IF NOT EXISTS` clause causes the error to be
suppressed if the branch already exists.

The optional `WITH` clause can be used to set properties
on the newly created branch.

The optional `FROM` clause can be used to set the source branch from which the
new branch is created.

## Examples

Create a new branch `audit` in the table `orders`:

```sql
CREATE BRANCH audit IN TABLE orders
```

Create a new branch `audit` in the table `orders` from the branch `dev`:

```sql
CREATE BRANCH audit IN TABLE orders FROM dev
```

## See also

{doc}`drop-branch`
8 changes: 7 additions & 1 deletion docs/src/main/sphinx/sql/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Synopsis

```text
DELETE FROM table_name [ WHERE condition ]
DELETE FROM table_name [ @ branch_name ] [ WHERE condition ]
```

## Description
Expand Down Expand Up @@ -32,6 +32,12 @@ Delete all orders:
DELETE FROM orders;
```

Delete all orders in the `audit` branch:

```sql
DELETE FROM orders @ audit;
```

## Limitations

Some connectors have limited or no support for `DELETE`.
Expand Down
8 changes: 7 additions & 1 deletion docs/src/main/sphinx/sql/deny.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```text
DENY ( privilege [, ...] | ( ALL PRIVILEGES ) )
ON ( table_name | TABLE table_name | SCHEMA schema_name)
ON [ BRANCH branch_name IN ] ( table_name | TABLE table_name | SCHEMA schema_name)
TO ( user | USER user | ROLE role )
```

Expand Down Expand Up @@ -39,6 +39,12 @@ Deny `SELECT` privilege on the table `orders` to everyone:
DENY SELECT ON orders TO ROLE PUBLIC;
```

Deny `INSERT` privilege on the `audit` branch of the `orders` table to user `alice`:

```sql
DENY INSERT ON BRANCH audit IN orders TO alice;
```

## Limitations

The system access controls as well as the connectors provided by default
Expand Down
27 changes: 27 additions & 0 deletions docs/src/main/sphinx/sql/drop-branch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# DROP BRANCH

## Synopsis

```text
DROP BRANCH [ IF EXISTS ] branch_name
IN TABLE table_name
```

## Description

Drops an existing branch.

The optional `IF EXISTS` clause causes the error to be suppressed if the branch
does not exist.

## Examples

Drop the branch `audit` in the table `orders`:

```sql
DROP BRANCH audit IN TABLE orders
```

## See also

{doc}`create-branch`
9 changes: 8 additions & 1 deletion docs/src/main/sphinx/sql/grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```text
GRANT ( privilege [, ...] | ( ALL PRIVILEGES ) )
ON ( table_name | TABLE table_name | SCHEMA schema_name)
ON [ BRANCH branch_name IN ] ( table_name | TABLE table_name | SCHEMA schema_name)
TO ( user | USER user | ROLE role )
[ WITH GRANT OPTION ]
```
Expand Down Expand Up @@ -51,6 +51,13 @@ Grant `SELECT` privilege on the table `orders` to everyone:
GRANT SELECT ON orders TO ROLE PUBLIC;
```

Grant `INSERT` privilege on the `audit` branch of the `orders` table to user
`alice`:

```sql
GRANT INSERT ON BRANCH audit IN orders TO alice;
```

## Limitations

Some connectors have no support for `GRANT`.
Expand Down
8 changes: 7 additions & 1 deletion docs/src/main/sphinx/sql/insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Synopsis

```text
INSERT INTO table_name [ ( column [, ... ] ) ] query
INSERT INTO table_name [ @ branch_name ] [ ( column [, ... ] ) ] query
```

## Description
Expand Down Expand Up @@ -52,6 +52,12 @@ INSERT INTO nation (nationkey, name, regionkey)
VALUES (26, 'POLAND', 3);
```

Insert a single row into `audit` branch of the `cities` table:

```sql
INSERT INTO cities @ audit VALUES (1, 'San Francisco');
```

## See also

{doc}`values`
11 changes: 10 additions & 1 deletion docs/src/main/sphinx/sql/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Synopsis

```text
MERGE INTO target_table [ [ AS ] target_alias ]
MERGE INTO target_table [ @ branch_name ] [ [ AS ] target_alias ]
USING { source_table | query } [ [ AS ] source_alias ]
ON search_condition
when_clause [...]
Expand Down Expand Up @@ -98,6 +98,15 @@ MERGE INTO accounts t USING monthly_accounts_update s
VALUES(s.customer, s.purchases, s.address)
```

Delete all customers mentioned in `audit` branch of the source table:

```sql
MERGE INTO accounts @ audit t USING monthly_accounts_update s
ON t.customer = s.customer
WHEN MATCHED
THEN DELETE
```

## Limitations

Any connector can be used as a source table for a `MERGE` statement.
Expand Down
9 changes: 8 additions & 1 deletion docs/src/main/sphinx/sql/revoke.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```text
REVOKE [ GRANT OPTION FOR ]
( privilege [, ...] | ALL PRIVILEGES )
ON ( table_name | TABLE table_name | SCHEMA schema_name )
ON [ BRANCH branch_name IN ] ( table_name | TABLE table_name | SCHEMA schema_name )
FROM ( user | USER user | ROLE role )
```

Expand Down Expand Up @@ -52,6 +52,13 @@ Revoke all privileges on the table `test` from user `alice`:
REVOKE ALL PRIVILEGES ON test FROM alice;
```

Revoke `INSERT` privilege on the `audit` branch of the `orders` table from user
`alice`:

```sql
REVOKE INSERT ON BRANCH audit IN orders FROM alice;
```

## Limitations

Some connectors have no support for `REVOKE`.
Expand Down
19 changes: 19 additions & 0 deletions docs/src/main/sphinx/sql/show-branches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SHOW BRANCHES

## Synopsis

```text
SHOW BRANCHES ( FROM | IN ) TABLE table_name
```

## Description

List the available branches.

## Examples

List the branches in the table `orders`:

```sql
SHOW BRANCHES IN TABLE orders
```
15 changes: 14 additions & 1 deletion docs/src/main/sphinx/sql/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Synopsis

```text
UPDATE table_name SET [ ( column = expression [, ... ] ) ] [ WHERE condition ]
UPDATE table_name [ @ branch_name ]
SET [ ( column = expression [, ... ] ) ] [ WHERE condition ]
```

## Description
Expand Down Expand Up @@ -55,6 +56,18 @@ SET
);
```

Update the status of all purchases that haven't been assigned a ship date
in the `audit` branch:

```sql
UPDATE
purchases @ audit
SET
status = 'OVERDUE'
WHERE
ship_date IS NULL;
```

## Limitations

Some connectors have limited or no support for `UPDATE`.
Expand Down