使用 SQL 列出 Postgres db 8.1 中的所有序列 [英] List all sequences in a Postgres db 8.1 with SQL

查看:14
本文介绍了使用 SQL 列出 Postgres db 8.1 中的所有序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个数据库从 postgres 转换为 mysql.

I'm converting a db from postgres to mysql.

由于我找不到一个可以自己解决问题的工具,我打算将所有 postgres 序列转换为 mysql 中具有自动增量值的自动增量 ID.

Since i cannot find a tool that does the trick itself, i'm going to convert all postgres sequences to autoincrement ids in mysql with autoincrement value.

那么,我如何使用 SQL 列出 Postgres 数据库(8.1 版本)中的所有序列以及有关使用它的表、下一个值等的信息查询?

So, how can i list all sequences in a Postgres DB (8.1 version) with information about the table in which it's used, the next value etc with a SQL query?

请注意,我无法在 8.4 版本中使用 information_schema.sequences 视图.

Be aware that i can't use the information_schema.sequences view in the 8.4 release.

推荐答案

以下查询给出所有序列的名称.

The following query gives names of all sequences.

SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';

通常一个序列被命名为 ${table}_id_seq.简单的正则表达式模式匹配将为您提供表名.

Typically a sequence is named as ${table}_id_seq. Simple regex pattern matching will give you the table name.

要获取序列的最后一个值,请使用以下查询:

To get last value of a sequence use the following query:

SELECT last_value FROM test_id_seq;

这篇关于使用 SQL 列出 Postgres db 8.1 中的所有序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆