|
| 1 | +--- |
| 2 | +title: SHOW SEQUENCES |
| 3 | +sidebar_position: 3 |
| 4 | +--- |
| 5 | + |
| 6 | +import FunctionDescription from '@site/src/components/FunctionDescription'; |
| 7 | + |
| 8 | +<FunctionDescription description="Introduced or updated: v1.2.742"/> |
| 9 | + |
| 10 | +Returns a list of the created sequences. |
| 11 | + |
| 12 | +## Syntax |
| 13 | + |
| 14 | +```sql |
| 15 | +SHOW SEQUENCES [ LIKE '<pattern>' | WHERE <expr> ] |
| 16 | +``` |
| 17 | + |
| 18 | +| Parameter | Description | |
| 19 | +|-----------|-----------------------------------------------------------------------------------------------------------------------------| |
| 20 | +| LIKE | Filters the results by their names using case-sensitive pattern matching. | |
| 21 | +| WHERE | Filters the results using an expression in the WHERE clause. You can filter based on any column in the result set, such as `name`, `start`, `interval`, `current`, `created_on`, `updated_on`, or `comment`. For example: `WHERE start > 0` or `WHERE name LIKE 's%'`. | |
| 22 | + |
| 23 | +## Examples |
| 24 | + |
| 25 | +```sql |
| 26 | +-- Create a sequence |
| 27 | +CREATE SEQUENCE seq; |
| 28 | + |
| 29 | +-- Show all sequences |
| 30 | +SHOW SEQUENCES; |
| 31 | + |
| 32 | +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ |
| 33 | +│ name │ start │ interval │ current │ created_on │ updated_on │ comment │ |
| 34 | +├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤ |
| 35 | +│ seq │ 1 │ 1 │ 1 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:48:49.749338 │ NULL │ |
| 36 | +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ |
| 37 | + |
| 38 | +-- Use the sequence in an INSERT statement |
| 39 | +CREATE TABLE tmp(a int, b uint64, c int); |
| 40 | +INSERT INTO tmp select 10,nextval(seq),20 from numbers(3); |
| 41 | + |
| 42 | +-- Show sequences after usage |
| 43 | +SHOW SEQUENCES; |
| 44 | + |
| 45 | +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ |
| 46 | +│ name │ start │ interval │ current │ created_on │ updated_on │ comment │ |
| 47 | +├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤ |
| 48 | +│ seq │ 1 │ 1 │ 4 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:49:14.302917 │ NULL │ |
| 49 | +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ |
| 50 | + |
| 51 | +-- Filter sequences using WHERE clause |
| 52 | +SHOW SEQUENCES WHERE start > 0; |
| 53 | + |
| 54 | +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ |
| 55 | +│ name │ start │ interval │ current │ created_on │ updated_on │ comment │ |
| 56 | +├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤ |
| 57 | +│ seq │ 1 │ 1 │ 4 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:49:14.302917 │ NULL │ |
| 58 | +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ |
| 59 | + |
| 60 | +-- Filter sequences by name pattern |
| 61 | +SHOW SEQUENCES LIKE 's%'; |
| 62 | + |
| 63 | +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ |
| 64 | +│ name │ start │ interval │ current │ created_on │ updated_on │ comment │ |
| 65 | +├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤ |
| 66 | +│ seq │ 1 │ 1 │ 4 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:49:14.302917 │ NULL │ |
| 67 | +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ |
0 commit comments