跳到主要内容

SHOW SEQUENCES

Introduced or updated: v1.2.742

返回已创建序列的列表。

语法​

SHOW SEQUENCES [ LIKE '<pattern>' | WHERE <expr> ]
参数描述
LIKE使用区分大小写的模式匹配按名称筛选结果。
WHERE使用 WHERE 子句中的表达式筛选结果。您可以根据结果集中的任何列进行筛选,例如 name、start、interval、current、created_on、updated_on 或 comment。例如:WHERE start > 0 或 WHERE name LIKE 's%'。

示例​

-- 创建一个序列
CREATE SEQUENCE seq;

-- 显示所有序列
SHOW SEQUENCES;

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ name │ start │ interval │ current │ created_on │ updated_on │ comment │
├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤
│ seq │ 1 │ 1 │ 1 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:48:49.749338 │ NULL │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

-- 在 INSERT 语句中使用序列
CREATE TABLE tmp(a int, b uint64, c int);
INSERT INTO tmp select 10,nextval(seq),20 from numbers(3);

-- 使用后显示序列
SHOW SEQUENCES;

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ name │ start │ interval │ current │ created_on │ updated_on │ comment │
├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤
│ seq │ 1 │ 1 │ 4 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:49:14.302917 │ NULL │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

-- 使用 WHERE 子句筛选序列
SHOW SEQUENCES WHERE start > 0;

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ name │ start │ interval │ current │ created_on │ updated_on │ comment │
├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤
│ seq │ 1 │ 1 │ 4 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:49:14.302917 │ NULL │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

-- 按名称模式筛选序列
SHOW SEQUENCES LIKE 's%';

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ name │ start │ interval │ current │ created_on │ updated_on │ comment │
├────────┼────────┼──────────┼─────────┼────────────────────────────┼────────────────────────────┼──────────────────┤
│ seq │ 1 │ 1 │ 4 │ 2025-05-20 02:48:49.749338 │ 2025-05-20 02:49:14.302917 │ NULL │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
欢迎体验 Databend Cloud

基于 Rust + 对象存储构建的新一代多模态数仓,一个平台即可进行 BI、向量、全文检索及地理空间分析。

支持标准 SQL,自动弹性伸缩,助您快速构建现代化数据平台。

注册即领 ¥200 代金券。

注册体验