Sequence exists but I can't find it in information_schema.sequences (PostgreSQL)
Asked Answered
N

1

7

I have created a sequence (let's call it my_seq) in a schema (let's call it my_schema) of my PostgreSQL (version 13) database. I am sure the sequence exists because I can find it in the result set of the query

select n.nspname as sequence_schema, 
       c.relname as sequence_name
from pg_class c 
  join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'S'
and n.nspname = 'my_schema'

However, if I run the following query

select sequence_name 
from information_schema.sequences 
where sequence_schema = 'my_schema'

my_seq isn't in the result set. I have run both queries with the same user I created the sequence with.

Can anybody help me find an explanation for this?

Normalcy answered 16/6, 2021 at 13:54 Comment(0)
N
8

The missing sequences are likely the ones used in an Identity column.

You can fetch all sequences using select * from pg_sequences;

To answer the why of the question: information_schema.sequences is a view, you can see its definition by running \d+ information_schema.sequences. There, we can see that it filters out objects being an internal dependency (AND NOT (EXISTS ... AND pg_depend.deptype = 'i'), which is the case of the sequences backing an Identity column.

Neary answered 16/6, 2021 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.