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
11 changes: 11 additions & 0 deletions _includes/sidebar-data-v19.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,17 @@
"urls": [
"/${VERSION}/diagnostics-reporting.html"
]
},
{
"title": "Sample Applications",
"items": [
{
"title": "MovR: Vehicle-Sharing App",
"urls": [
"/${VERSION}/movr.html"
]
}
]
}
]
},
Expand Down
39 changes: 21 additions & 18 deletions _includes/v19.2/computed-columns/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@ In this example, let's create a simple table with a computed column:

{% include copy-clipboard.html %}
~~~ sql
> CREATE TABLE names (
id INT PRIMARY KEY,
first_name STRING,
last_name STRING,
full_name STRING AS (CONCAT(first_name, ' ', last_name)) STORED
);
> CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
city STRING,
first_name STRING,
last_name STRING,
full_name STRING AS (CONCAT(first_name, ' ', last_name)) STORED,
address STRING,
credit_card STRING,
dl STRING UNIQUE CHECK (LENGTH(dl) < 8)
);
~~~

Then, insert a few rows of data:

{% include copy-clipboard.html %}
~~~ sql
> INSERT INTO names (id, first_name, last_name) VALUES
(1, 'Lola', 'McDog'),
(2, 'Carl', 'Kimball'),
(3, 'Ernie', 'Narayan');
> INSERT INTO users (first_name, last_name) VALUES
('Lola', 'McDog'),
('Carl', 'Kimball'),
('Ernie', 'Narayan');
~~~

{% include copy-clipboard.html %}
~~~ sql
> SELECT * FROM names;
> SELECT * FROM users;
~~~
~~~
+----+------------+-------------+----------------+
| id | first_name | last_name | full_name |
+----+------------+-------------+----------------+
| 1 | Lola | McDog | Lola McDog |
| 2 | Carl | Kimball | Carl Kimball |
| 3 | Ernie | Narayan | Ernie Narayan |
+----+------------+-------------+----------------+
id | city | first_name | last_name | full_name | address | credit_card | dl
+--------------------------------------+------+------------+-----------+---------------+---------+-------------+------+
5740da29-cc0c-47af-921c-b275d21d4c76 | NULL | Ernie | Narayan | Ernie Narayan | NULL | NULL | NULL
e7e0b748-9194-4d71-9343-cd65218848f0 | NULL | Lola | McDog | Lola McDog | NULL | NULL | NULL
f00e4715-8ca7-4d5a-8de5-ef1d5d8092f3 | NULL | Carl | Kimball | Carl Kimball | NULL | NULL | NULL
(3 rows)
~~~

The `full_name` column is computed from the `first_name` and `last_name` columns without the need to define a [view](views.html).
78 changes: 48 additions & 30 deletions _includes/v19.2/faq/auto-generate-unique-ids.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,67 @@

{% include copy-clipboard.html %}
~~~ sql
> CREATE TABLE t1 (id UUID PRIMARY KEY DEFAULT gen_random_uuid(), name STRING);
> CREATE TABLE users (
id UUID NOT NULL DEFAULT gen_random_uuid(),
city STRING NOT NULL,
name STRING NULL,
address STRING NULL,
credit_card STRING NULL,
CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC),
FAMILY "primary" (id, city, name, address, credit_card)
);
~~~

{% include copy-clipboard.html %}
~~~ sql
> INSERT INTO t1 (name) VALUES ('a'), ('b'), ('c');
> INSERT INTO users (name, city) VALUES ('Petee', 'new york'), ('Eric', 'seattle'), ('Dan', 'seattle');
~~~

{% include copy-clipboard.html %}
~~~ sql
> SELECT * FROM t1;
> SELECT * FROM users;
~~~

~~~
+--------------------------------------+------+
| id | name |
+--------------------------------------+------+
| 60853a85-681d-4620-9677-946bbfdc8fbc | c |
| 77c9bc2e-76a5-4ebc-80c3-7ad3159466a1 | b |
| bd3a56e1-c75e-476c-b221-0da9d74d66eb | a |
+--------------------------------------+------+
id | city | name | address | credit_card
+--------------------------------------+----------+-------+---------+-------------+
cf8ee4e2-cd74-449a-b6e6-a0fb2017baa4 | new york | Petee | NULL | NULL
2382564e-702f-42d9-a139-b6df535ae00a | seattle | Eric | NULL | NULL
7d27e40b-263a-4891-b29b-d59135e55650 | seattle | Dan | NULL | NULL
(3 rows)
~~~

Alternatively, you can use the [`BYTES`](bytes.html) column with the `uuid_v4()` function as the default value instead:

{% include copy-clipboard.html %}
~~~ sql
> CREATE TABLE t2 (id BYTES PRIMARY KEY DEFAULT uuid_v4(), name STRING);
> CREATE TABLE users2 (
id BYTES DEFAULT uuid_v4(),
city STRING NOT NULL,
name STRING NULL,
address STRING NULL,
credit_card STRING NULL,
CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC),
FAMILY "primary" (id, city, name, address, credit_card)
);
~~~

{% include copy-clipboard.html %}
~~~ sql
> INSERT INTO t2 (name) VALUES ('a'), ('b'), ('c');
> INSERT INTO users2 (name, city) VALUES ('Anna', 'new york'), ('Jonah', 'seattle'), ('Terry', 'chicago');
~~~

{% include copy-clipboard.html %}
~~~ sql
> SELECT * FROM t2;
> SELECT * FROM users;
~~~

~~~
+---------------------------------------------------+------+
| id | name |
+---------------------------------------------------+------+
| "\x9b\x10\xdc\x11\x9a\x9cGB\xbd\x8d\t\x8c\xf6@vP" | a |
| "\xd9s\xd7\x13\n_L*\xb0\x87c\xb6d\xe1\xd8@" | c |
| "\uac74\x1dd@B\x97\xac\x04N&\x9eBg\x86" | b |
+---------------------------------------------------+------+
id | city | name | address | credit_card
+------------------------------------------------+----------+-------+---------+-------------+
4\244\277\323/\261M\007\213\275*\0060\346\025z | chicago | Terry | NULL | NULL
\273*t=u.F\010\274f/}\313\332\373a | new york | Anna | NULL | NULL
\004\\\364nP\024L)\252\364\222r$\274O0 | seattle | Jonah | NULL | NULL
(3 rows)
~~~

Expand All @@ -60,27 +72,33 @@

{% include copy-clipboard.html %}
~~~ sql
> CREATE TABLE t3 (id INT PRIMARY KEY DEFAULT unique_rowid(), name STRING);
> CREATE TABLE users3 (
id INT DEFAULT unique_rowid(),
city STRING NOT NULL,
name STRING NULL,
address STRING NULL,
credit_card STRING NULL,
CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC),
FAMILY "primary" (id, city, name, address, credit_card)
);
~~~

{% include copy-clipboard.html %}
~~~ sql
> INSERT INTO t3 (name) VALUES ('a'), ('b'), ('c');
> INSERT INTO users3 (name, city) VALUES ('Blake', 'chicago'), ('Hannah', 'seattle'), ('Bobby', 'seattle');
~~~

{% include copy-clipboard.html %}
~~~ sql
> SELECT * FROM t3;
> SELECT * FROM users3;
~~~

~~~
+--------------------+------+
| id | name |
+--------------------+------+
| 293807573840855041 | a |
| 293807573840887809 | b |
| 293807573840920577 | c |
+--------------------+------+
id | city | name | address | credit_card
+--------------------+---------+--------+---------+-------------+
469048192112197633 | chicago | Blake | NULL | NULL
469048192112263169 | seattle | Hannah | NULL | NULL
469048192112295937 | seattle | Bobby | NULL | NULL
(3 rows)
~~~

Expand Down
10 changes: 5 additions & 5 deletions _includes/v19.2/misc/force-index-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ you can check the scan direction with:

{% include copy-clipboard.html %}
~~~ sql
> EXPLAIN (opt) SELECT * FROM kv@{FORCE_INDEX=primary,DESC};
> EXPLAIN (opt) SELECT * FROM users@{FORCE_INDEX=primary,DESC};
~~~

~~~
text
-------------------------------------
scan kv,rev
└── flags: force-index=primary,rev
text
+-------------------------------------+
scan users,rev
└── flags: force-index=primary,rev
(2 rows)
~~~

Expand Down
2 changes: 1 addition & 1 deletion _includes/v19.2/performance/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To reproduce the performance demonstrated in this tutorial:

### Schema

Your schema and data will be based on our open-source, fictional peer-to-peer ride-sharing application,[MovR](https://github.com/cockroachdb/movr).
Your schema and data will be based on our open-source, fictional peer-to-peer vehicle-sharing application, [MovR](movr.html).

<img src="{{ 'images/v19.2/perf_tuning_movr_schema.png' | relative_url }}" alt="Perf tuning schema" style="max-width:100%" />

Expand Down
36 changes: 36 additions & 0 deletions _includes/v19.2/sql/movr-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- Run [`cockroach demo movr`](cockroach-demo.html) to open an interactive SQL shell to a temporary, in-memory cluster with the `movr` database preloaded and set as the [current database](sql-name-resolution.html#current-database).

{% include copy-clipboard.html %}
~~~ shell
$ cockroach demo movr
~~~

- Use [`cockroach workload`](cockroach-workload.html):

1. Start an [insecure](start-a-local-cluster.html) local cluster.

{% include copy-clipboard.html %}
~~~ shell
$ cockroach start --insecure <flags>
~~~

2. Run `cockroach workload init movr` with the appropriate flags and [connection string](connection-parameters.html) to initialize and populate the `movr` database on your running cluster.

{% include copy-clipboard.html %}
~~~ shell
$ cockroach workload init movr <flags>
~~~

3. Open an interactive SQL shell to the cluster with the [`cockroach sql`](use-the-built-in-sql-client.html) command.

{% include copy-clipboard.html %}
~~~ shell
$ cockroach sql <flags>
~~~

4. Set `movr` as the [current database](sql-name-resolution.html#current-database) for the session.

{% include copy-clipboard.html %}
~~~ sql
> USE movr;
~~~
10 changes: 10 additions & 0 deletions _includes/v19.2/sql/movr-statements-no-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The following examples use MovR, a fictional vehicle-sharing application, to demonstrate CockroachDB SQL statements. For more information about the MovR example application, see [MovR: A Global Vehicle-sharing App](movr.html).

To follow along, do the following:

1. Start up a [secure](secure-a-cluster.html) or [insecure](start-a-local-cluster.html) local cluster.
1. Open an interactive SQL shell to the cluster with the [`cockroach sql`](use-the-built-in-sql-client.html) command.
1. Create the `movr` database with the [`CREATE DATABASE`](create-table.html) statement.
1. Set `movr` as the [current database](sql-name-resolution.html#current-database) for the session with the [`SET`](set-vars.html) statement.

You can alternatively run `cockroach demo` to open an interactive SQL shell to a temporary, in-memory cluster, and then complete steps 3 and 4.
7 changes: 7 additions & 0 deletions _includes/v19.2/sql/movr-statements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Setup

The following examples use MovR, a fictional vehicle-sharing application, to demonstrate CockroachDB SQL statements. For more information about the MovR example application and dataset, see [MovR: A Global Vehicle-sharing App](movr.html).

To follow along with the example statements, do one of the following:

{% include {{page.version.version}}/sql/movr-start.md %}
2 changes: 1 addition & 1 deletion v19.2/add-constraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The user must have the `CREATE` [privilege](authorization.html#assign-privileges
-----------|-------------
`table_name` | The name of the table containing the column you want to constrain.
`constraint_name` | The name of the constraint, which must be unique to its table and follow these [identifier rules](keywords-and-identifiers.html#identifiers).
`constraint_elem` | The [`CHECK`](check.html), [foreign key](foreign-key.html), [`UNIQUE`](unique.html) constraint you want to add. <br/><br/>Adding/changing a `DEFAULT` constraint is done through [`ALTER COLUMN`](alter-column.html). <br/><br/>Adding/changing the table's `PRIMARY KEY` is not supported through `ALTER TABLE`; it can only be specified during [table creation](create-table.html#create-a-table-primary-key-defined).
`constraint_elem` | The [`CHECK`](check.html), [foreign key](foreign-key.html), [`UNIQUE`](unique.html) constraint you want to add. <br/><br/>Adding/changing a `DEFAULT` constraint is done through [`ALTER COLUMN`](alter-column.html). <br/><br/>Adding/changing the table's `PRIMARY KEY` is not supported through `ALTER TABLE`; it can only be specified during [table creation](create-table.html).

## Viewing schema changes

Expand Down
1 change: 1 addition & 0 deletions v19.2/cockroach-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Workload | Description
---------|------------
`bank` | A `bank` database, with one `bank` table containing account details.
`intro` | An `intro` database, with one table, `mytable`, with a hidden message.
`movr` | A `movr` database, with several tables of data for the [MovR example application](movr.html).
`startrek` | A `startrek` database, with two tables, `episodes` and `quotes`.
`tpcc` | A `tpcc` database, with a rich schema of multiple tables.

Expand Down
Loading