|
| 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 | +返回已创建序列的列表。 |
| 11 | + |
| 12 | +## 语法 |
| 13 | + |
| 14 | +```sql |
| 15 | +SHOW SEQUENCES [ LIKE '<pattern>' | WHERE <expr> ] |
| 16 | +``` |
| 17 | + |
| 18 | +| 参数 | 描述 | |
| 19 | +|-----------|---------------------------------------------------------------------------------------------------------------------------| |
| 20 | +| LIKE | 使用区分大小写的模式匹配按名称筛选结果。 | |
| 21 | +| WHERE | 使用 WHERE 子句中的表达式筛选结果。您可以根据结果集中的任何列进行筛选,例如 `name`、`start`、`interval`、`current`、`created_on`、`updated_on` 或 `comment`。例如:`WHERE start > 0` 或 `WHERE name LIKE 's%'`。 | |
| 22 | + |
| 23 | +## 示例 |
| 24 | + |
| 25 | +```sql |
| 26 | +-- 创建一个序列 |
| 27 | +CREATE SEQUENCE seq; |
| 28 | + |
| 29 | +-- 显示所有序列 |
| 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 | +-- 在 INSERT 语句中使用序列 |
| 39 | +CREATE TABLE tmp(a int, b uint64, c int); |
| 40 | +INSERT INTO tmp select 10,nextval(seq),20 from numbers(3); |
| 41 | + |
| 42 | +-- 使用后显示序列 |
| 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 | +-- 使用 WHERE 子句筛选序列 |
| 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 | +-- 按名称模式筛选序列 |
| 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