Skip to content

Commit 2a368ce

Browse files
committed
Update with taroface feedback (1)
1 parent a37be22 commit 2a368ce

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/current/v25.2/create-table-as.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The user must have the `CREATE` [privilege]({% link {{ page.version.version }}/s
7878
`create_as_col_qual_list` | An optional column definition, which may include [primary key constraints]({% link {{ page.version.version }}/primary-key.md %}) and [column family assignments]({% link {{ page.version.version }}/column-families.md %}).
7979
`family_def` | An optional [column family definition]({% link {{ page.version.version }}/column-families.md %}). Column family names must be unique within the table but can have the same name as columns, constraints, or indexes.
8080
`create_as_constraint_def` | An optional [primary key constraint]({% link {{ page.version.version }}/primary-key.md %}).
81-
`select_stmt` | A [selection query]({% link {{ page.version.version }}/selection-queries.md %}) to provide the data.
81+
`select_stmt` | A [selection query]({% link {{ page.version.version }}/select-clause.md %}) to provide the data.
8282
`opt_persistence_temp_table` | Defines the table as a session-scoped temporary table. For more information, see [Temporary Tables]({% link {{ page.version.version }}/temporary-tables.md %}).<br><br>Note that the `LOCAL`, `GLOBAL`, and `UNLOGGED` options are no-ops, allowed by the parser for PostgreSQL compatibility.<br><br>**Support for temporary tables is [in preview]({% link {{ page.version.version }}/cockroachdb-feature-availability.md %}#temporary-objects)**.
8383
`opt_with_storage_parameter_list` | A comma-separated list of [spatial index tuning parameters]({% link {{ page.version.version }}/spatial-indexes.md %}#index-tuning-parameters). Supported parameters include `fillfactor`, `s2_max_level`, `s2_level_mod`, `s2_max_cells`, `geometry_min_x`, `geometry_max_x`, `geometry_min_y`, and `geometry_max_y`. The `fillfactor` parameter is a no-op, allowed for PostgreSQL-compatibility.<br><br>For details, see [Spatial index tuning parameters]({% link {{ page.version.version }}/spatial-indexes.md %}#index-tuning-parameters). For an example, see [Create a spatial index that uses all of the tuning parameters]({% link {{ page.version.version }}/spatial-indexes.md %}#create-a-spatial-index-that-uses-all-of-the-tuning-parameters).
8484
`ON COMMIT PRESERVE ROWS` | This clause is a no-op, allowed by the parser for PostgreSQL compatibility. CockroachDB only supports session-scoped [temporary tables]({% link {{ page.version.version }}/temporary-tables.md %}), and does not support the clauses `ON COMMIT DELETE ROWS` and `ON COMMIT DROP`, which are used to define transaction-scoped temporary tables in PostgreSQL.
@@ -302,40 +302,35 @@ You can define the [column families]({% link {{ page.version.version }}/column-f
302302
The timestamp must be within the [garbage collection (GC) window]({% link {{ page.version.version }}/architecture/storage-layer.md %}#garbage-collection) of the source table for the data to be available.
303303
{{site.data.alerts.end}}
304304

305-
The syntax for creating a new table from a historical table at a given timestamp is as follows; this example creates a new table at the most recent timestamp that can perform a [follower read]({% link {{ page.version.version }}/follower-reads.md %}).
305+
The following example creates a new table from the [`movr`]({% link {{ page.version.version }}/movr.md %}) dataset at the most recent timestamp that can perform a [follower read]({% link {{ page.version.version }}/follower-reads.md %}).
306306

307307
{% include_cached copy-clipboard.html %}
308308
~~~ sql
309309
CREATE TABLE analysis_vehicle_location_histories
310-
AS SELECT * FROM vehicle_location_histories
310+
AS SELECT * FROM movr.vehicle_location_histories
311311
AS OF SYSTEM TIME follower_read_timestamp();
312312
~~~
313313

314+
~~~
315+
CREATE TABLE AS
316+
~~~
317+
314318
#### Undo an accidental table deletion
315319

316-
The following steps show how to undo an accidental table deletion using `CREATE TABLE AS ... AS OF SYSTEM TIME`.
320+
The following steps use a table from the [`movr`]({% link {{ page.version.version }}/movr.md %}) dataset to show how to undo an accidental table deletion using `CREATE TABLE AS ... AS OF SYSTEM TIME`.
317321

318-
1. Create and populate a table:
319-
320-
{% include_cached copy-clipboard.html %}
321-
~~~ sql
322-
CREATE TABLE customers (
323-
id INT PRIMARY KEY,
324-
name STRING
325-
);
326-
327-
INSERT INTO customers (id, name) VALUES (1, 'Alice'), (2, 'Bob');
328-
~~~
329-
330-
1. Get a timestamp from before the table is deleted:
322+
1. Get a timestamp before the table is deleted in an upcoming step:
331323

332324
{% include_cached copy-clipboard.html %}
333325
~~~ sql
334326
SELECT now();
335327
~~~
336328

337329
~~~
338-
2025-06-09 19:55:40.286833+00
330+
now
331+
--------------------------------
332+
2025-06-17 15:04:15.82632+00
333+
(1 row)
339334
~~~
340335

341336
1. Wait a few seconds to simulate time passing (adjust as needed):
@@ -345,18 +340,29 @@ The following steps show how to undo an accidental table deletion using `CREATE
345340
SELECT pg_sleep(5);
346341
~~~
347342

343+
~~~
344+
pg_sleep
345+
------------
346+
t
347+
(1 row)
348+
~~~
349+
348350
1. Drop the original table:
349351

350352
{% include_cached copy-clipboard.html %}
351353
~~~ sql
352-
DROP TABLE customers;
354+
DROP TABLE movr.vehicle_location_histories;
355+
~~~
356+
357+
~~~
358+
DROP TABLE
353359
~~~
354360

355-
1. Restore the table using the [`AS OF SYSTEM TIME`]({% link {{ page.version.version }}/as-of-system-time.md %}) clause:
361+
1. Restore the table using the [`AS OF SYSTEM TIME`]({% link {{ page.version.version }}/as-of-system-time.md %}) clause and the timestamp you obtained before dropping the table:
356362

357363
{% include_cached copy-clipboard.html %}
358364
~~~ sql
359-
CREATE TABLE customers_restored AS SELECT * FROM customers AS OF SYSTEM TIME '2025-06-09 19:55:40.286833+00';
365+
CREATE TABLE movr.vehicle_location_histories AS SELECT * FROM movr.vehicle_location_histories AS OF SYSTEM TIME '2025-06-17 15:04:15.82632+00';
360366
~~~
361367

362368
~~~

0 commit comments

Comments
 (0)