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

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

问题描述

我将一个db从postgres转换为mysql。

I'm converting a db from postgres to mysql.

由于我找不到一个工具来执行这个技巧本身,我要转换所有postgres序列自动增量ids在mysql与autoincrement值。

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.

因此,如何列出 Postgres 数据库( 8.1 版本)中所有序列的信息,下一个值等与SQL查询?

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?

请注意,我不能使用 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天全站免登陆