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
                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.
You should use the query "select sequence_name from all_sequences;" to find out all sequences accessible to the schema user.
To view the DDL of the sequence, use this
select * from information_schema.sequences where sequence_name='<your_sequence_name_in_lower_case>'
                        If I understand correctly, you can use `INFORMATION_SCHEMA.sequences.
There documentation is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With