Get the sequence name corresponding to a GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY column

From: Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Get the sequence name corresponding to a GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY column
Date: 2023-02-06 17:17:17
Message-ID: DBAP191MB12892E942BD10BC2F46A354EB0DA9@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!

Assuming that a sequence is used to implement GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY

Is there any built-in function that returns the underlying sequence name used for such column?

Otherwise, an SQL query to return the sequence name?

I need the sequence name, in order to reset it (setval) or to get the last generated value (currval) ...

The query must work with all PostgreSQL versions 10 to 15 ...

Seb

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marcos Pegoraro 2023-02-06 17:33:01 Re: Understanding years part of Interval
Previous Message Philip Semanchuk 2023-02-06 17:04:48 ALTER COLUMN to change GENERATED ALWAYS AS expression?