Fwd: Renaming sequences

From: Zahid Rahman <zahidr1000(at)gmail(dot)com>
To: pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: Fwd: Renaming sequences
Date: 2019-12-18 06:08:04
Message-ID: CAPGSW3TZ4YpguUb=B=2mZtb=MP5HCFM=vZ=VbPnHb2LCHAS1GA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

If you are referring to a sequence which meets the same definition below.
That is to say a persistent number generator.

Surely by changing the sequence name then any code using that sequence
by name will fail. That's from an application developer's view.

A *sequence* in*PostgreSQL* is a user-defined schema-bound object that
generates a*sequence* of integers based on a specified specification. To
create a *sequence* in *PostgreSQL*, you use the CREATE *SEQUENCE *
statement.

After a sequence is created, you use the

functions nextval, currval, and setval to operate on the sequence. These
functions are documented in Section 9.16
<https://www.postgresql.org/docs/9.5/functions-sequence.html>.

Although you cannot update a sequence directly, you can use a query like:

SELECT * FROM name;

On Wed, 18 Dec 2019, 05:33 Mike Dewhirst, <miked(at)dewhirst(dot)com(dot)au> wrote:

> Are there any consequences for renaming sequences to match the tables
> which own them?
>
> In an existing production Django project I have just converted auth.user
> into common.user and company.userprofile into common.userprofile.
>
> Having gone through the migration process more or less unscathed the
> original sequences are owned by the renamed tables. Eg
> public.auth_user_id_seq is owned by public.common_user.id
>
> Everything seems to work fine but my unit tests are playing up and error
> messages are showing the original (and still correct) sequence names. It
> would make much visual sense to me now and especially to the future me (or
> anyone else) if the sequences were renamed as well.
>
> I know how I could do it but I just need to know if I should.
>
> Thanks for any advice
>
> Mike
>
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Mike Dewhirst 2019-12-18 06:23:02 Re: Renaming sequences
Previous Message Mike Dewhirst 2019-12-18 05:32:54 Renaming sequences