Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 6.59 KB

File metadata and controls

67 lines (50 loc) · 6.59 KB
title SHOW SEQUENCES
sidebar_position 3

import FunctionDescription from '@site/src/components/FunctionDescription';

返回已创建序列的列表。

语法

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

示例

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

-- 显示所有序列
SHOW SEQUENCES;

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

-- 在 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    │      1142025-05-20 02:48:49.7493382025-05-20 02:49:14.302917NULL             │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

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

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

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

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