Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view sequence details with a SQL

Tags:

sql

postgresql

As you know, we can view the details of a sequence by using '\d' command. I would like to know if there is a way to get these information with a SQL query so that I can view the details for all sequences in PostgreSQL database.

Eventually, the left 'Column' will be displayed horizontally like we see normally when we use a sql statement.

postgres=# \d next_empno
         Sequence "public.next_empno"
    Column     |  Type   |        Value        
---------------+---------+---------------------
 sequence_name | name    | next_empno
 last_value    | bigint  | 8000
 start_value   | bigint  | 8000
 increment_by  | bigint  | 1
 max_value     | bigint  | 9223372036854775807
 min_value     | bigint  | 1
 cache_value   | bigint  | 1
 log_cnt       | bigint  | 0
 is_cycled     | boolean | f
 is_called     | boolean | f
like image 747
Sigularity Avatar asked Jul 31 '16 02:07

Sigularity


People also ask

How do I view a sequence in SQL?

The syntax to a view the properties of a sequence in SQL Server (Transact-SQL) is: SELECT * FROM sys. sequences WHERE name = 'sequence_name'; sequence_name.

How do I view a sequence in SQL Developer?

You should use the query "select sequence_name from all_sequences;" to find out all sequences accessible to the schema user.


2 Answers

To view the DDL of the sequence, use this

select * from information_schema.sequences where sequence_name='<your_sequence_name_in_lower_case>'
like image 177
allkenang Avatar answered Oct 23 '22 04:10

allkenang


If I understand correctly, you can use `INFORMATION_SCHEMA.sequences.

There documentation is here.

like image 33
Gordon Linoff Avatar answered Oct 23 '22 03:10

Gordon Linoff