public inbox for [email protected]  
help / color / mirror / Atom feed
How to find all current sequence IDs
4+ messages / 3 participants
[nested] [flat]

* How to find all current sequence IDs
@ 2024-02-21 22:06  Campbell, Lance <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Campbell, Lance @ 2024-02-21 22:06 UTC (permalink / raw)
  To: [email protected] <[email protected]>

Is there a way to get a list of all sequences, the schema it is used in, and the current sequence number in use?

The below SQL will give me the schema and sequences. It does not give me the current sequence number in use.

SELECT sequence_schema, sequence_name
FROM information_schema.sequences
ORDER BY sequence_name ;

Thanks,

Lance Campbell
University of Illinois


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to find all current sequence IDs
@ 2024-02-21 22:13  Tom Lane <[email protected]>
  parent: Campbell, Lance <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2024-02-21 22:13 UTC (permalink / raw)
  To: Campbell, Lance <[email protected]>; +Cc: [email protected] <[email protected]>

"Campbell, Lance" <[email protected]> writes:
> Is there a way to get a list of all sequences, the schema it is used in, and the current sequence number in use?

Try something like

select relname, relnamespace::regnamespace, pg_sequence_last_value(oid)
from pg_class where relkind = 'S';

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to find all current sequence IDs
@ 2024-02-21 23:17  Nisarg Patel <[email protected]>
  parent: Tom Lane <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Nisarg Patel @ 2024-02-21 23:17 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Campbell, Lance <[email protected]>; [email protected]

This has worked for me in the past:
select schemaname, sequencename, last_value
from pg_sequences;

Thank you,
Nisarg

On Wed, Feb 21, 2024, 5:14 PM Tom Lane <[email protected]> wrote:

> "Campbell, Lance" <[email protected]> writes:
> > Is there a way to get a list of all sequences, the schema it is used in,
> and the current sequence number in use?
>
> Try something like
>
> select relname, relnamespace::regnamespace, pg_sequence_last_value(oid)
> from pg_class where relkind = 'S';
>
>                         regards, tom lane
>
>
>


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* RE: How to find all current sequence IDs
@ 2024-02-29 14:49  Campbell, Lance <[email protected]>
  parent: Nisarg Patel <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Campbell, Lance @ 2024-02-29 14:49 UTC (permalink / raw)
  To: Nisarg Patel <[email protected]>; Tom Lane <[email protected]>; +Cc: [email protected] <[email protected]>

That worked great. Thanks so much.

From: Nisarg Patel <[email protected]>
Sent: Wednesday, February 21, 2024 5:17 PM
To: Tom Lane <[email protected]>
Cc: Campbell, Lance <[email protected]>; [email protected]
Subject: Re: How to find all current sequence IDs

This has worked for me in the past:
select schemaname, sequencename, last_value
from pg_sequences;

Thank you,
Nisarg
On Wed, Feb 21, 2024, 5:14 PM Tom Lane <[email protected]<mailto:[email protected]>> wrote:
"Campbell, Lance" <[email protected]<mailto:[email protected]>> writes:
> Is there a way to get a list of all sequences, the schema it is used in, and the current sequence number in use?

Try something like

select relname, relnamespace::regnamespace, pg_sequence_last_value(oid)
from pg_class where relkind = 'S';

                        regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2024-02-29 14:49 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21 22:06 How to find all current sequence IDs Campbell, Lance <[email protected]>
2024-02-21 22:13 ` Tom Lane <[email protected]>
2024-02-21 23:17   ` Nisarg Patel <[email protected]>
2024-02-29 14:49     ` Campbell, Lance <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox