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

From: Thomas Kellerer <shammat(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Get the sequence name corresponding to a GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY column
Date: 2023-02-06 17:43:52
Message-ID: d0102694-471a-08c2-faf7-27e0366cb834@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sebastien Flaesch schrieb am 06.02.2023 um 18:17:
> 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 ...

Despite its name pg_get_serial_sequence() also works for identity columns

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Torsten Förtsch 2023-02-06 17:46:16 plpgsql: ambiguous column reference in ON CONFLICT clause
Previous Message Marcos Pegoraro 2023-02-06 17:33:01 Re: Understanding years part of Interval