Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ihTNL-0003I8-Ql for pgsql-novice@arkaria.postgresql.org; Wed, 18 Dec 2019 07:04:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ihTNK-00013T-CN for pgsql-novice@arkaria.postgresql.org; Wed, 18 Dec 2019 07:04:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ihTNJ-00013I-QU for pgsql-novice@lists.postgresql.org; Wed, 18 Dec 2019 07:04:02 +0000 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ihTNF-0005T2-0S for pgsql-novice@lists.postgresql.org; Wed, 18 Dec 2019 07:04:00 +0000 Received: by mail-oi1-x244.google.com with SMTP id c16so461456oic.3 for ; Tue, 17 Dec 2019 23:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eR26LGvZNskA7Ocl00QG5WmRRGaMjpqSPJDl/ddsYt0=; b=CrXuJG2Nyvz9atfFHCKIQSjZTjsXNpts1WgghYgOJYjL2/NDVCpVLwBYfiqzhcgHvp L38l84dR33yXNgab5Nt5xyEG0JwHFpUJ5juEZtStzz0ACe2oo+aQBvQCm+oqFKloGEqP 4UxBswXs0+wm3/Tc4PsxnsSOS5AY7M/eGAkGNPhVY+IvKtG9qBxCi3hpBRAvzo3BSPd3 qiiP1pIOsCIIqQhuG4IKcPBcNGiH2L432PkZPWpHcGw5wHGeeER1X0Hcd5gVDBlA7ttI tIF9j+wXhLPvjkifhqjovYzOBw4BPrTenoC0YpwLeyhaAHYb872wBjGpPNOTZdLF3aJY ugHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eR26LGvZNskA7Ocl00QG5WmRRGaMjpqSPJDl/ddsYt0=; b=KoWdq8VWfJ890y8AejEA2mSYmCzQhsDjg8HFNKnglzDiaQXwk/18lLusmd2CnBqYub 6F8u1mNFhCfcKL/epPr8GNsLoswlk+ALdQ+0wI+87MYC2p/3edTyk3EiH9bdlJ7josTw 9qdW71/qmPCKDLm84EyjO5y1A6RsCVtjVF6NUHtJu84O9duqH+8E2vGFuBI0axB7FKT1 Vqhjl6dFzrauADzWhZRvRmUV6AUUekjBxPEBRa7lGWbIt/7cL1aMT8xNju1sY3hVhhNF v2nmLCBh3n/OP7vokrkr/+DsCyHxQtOk+tz3Vj7gs8/G2vqtPJhSFEWUFHknI+0e533q 7XTA== X-Gm-Message-State: APjAAAU6hsUBQv+3BLRzZLg8xamMBap8hNhV5GGG/tojDoJbsZt3mq8Z 83zSvXF/MQsnPfDCHWsyaSP1o2shfJq+eN/zNUo= X-Google-Smtp-Source: APXvYqzQfKmUao4f08aPB8LrmHaKX/9L2Ks0uw0VormoNz41JaqfDHJ7RyDD3L8NPgQWSDuFHm68FSeVWhKZjpm4qvY= X-Received: by 2002:aca:f555:: with SMTP id t82mr41267oih.103.1576652636094; Tue, 17 Dec 2019 23:03:56 -0800 (PST) MIME-Version: 1.0 References: <4a4dd791-5904-5ab9-f066-c24ca19e20d7@dewhirst.com.au> <711c4f7f-11a7-8065-9906-d2b9dfc1dbb5@dewhirst.com.au> In-Reply-To: <711c4f7f-11a7-8065-9906-d2b9dfc1dbb5@dewhirst.com.au> From: Zahid Rahman Date: Wed, 18 Dec 2019 07:03:44 +0000 Message-ID: Subject: Re: Renaming sequences To: Mike Dewhirst Cc: pgsql-novice@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000004f050a0599f50ce5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000004f050a0599f50ce5 Content-Type: text/plain; charset="UTF-8" > The fact that it is working with mismatched names . I just had a quick look at django. It is not something I know of or use. Just a front end framework using python language as far as I can see. >mismatched names I suspect you have sequences with different names. Use Select * from sequence_name_a; Select * from sequence_name_b; If you get error free results then that means you have sequences with different names. If I understand what you are to begin with. On Wed, 18 Dec 2019, 06:23 Mike Dewhirst, wrote: > On 18/12/2019 5:03 pm, Zahid Rahman wrote: > > 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. > > > Yes. > > I think I'd better ask on the Django users list. > > The fact that it is working with mismatched names probably means it would > stop working if I adjusted them. Django probably reads the migration record > to establish which sequence to use. > > Thanks > > > > 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 > . > > 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, 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 >> >> > --0000000000004f050a0599f50ce5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> The fact= that it is working with mismatched names .
<= span style=3D"font-family:sans-serif">
I just had a quick look at django. It is not someth= ing I know of or use.
Just a front end framework using python language as far as I can see.

>mismatched names

I suspect you have sequences with different names.
Use
Select= * from sequence_name_a;
Select * from sequence_name_b;

If you get error free results then = that means you have sequences with different names.

If I understand=C2=A0 what you= are to begin with.





On Wed, 18 Dec 2019, 06:23 Mik= e Dewhirst, <miked@dewhirst.com.au> wrot= e:
=20 =20 =20
On 18/12/2019 5:03 pm, Zahid Rahman wrote:
=20

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

Surely by=C2=A0 changing=C2=A0 the sequence name then any=C2=A0 code u= sing that sequence by name will fail. That's from an application developer's view.


Yes.

I think I'd better ask on the Django users list.

The fact that it is working with mismatched names probably means it would stop working if I adjusted them. Django probably reads the migration record to establish which sequence to use.

Thanks



A=C2=A0sequence=C2=A0in<= b style=3D"max-height:999999px;color:rgb(60,64,67);font-family:roboto,helve= ticaneue,arial,sans-serif;font-size:18px">PostgreSQL=C2=A0is a user-defined schema-bound object that generates asequence=C2=A0of integers based on a specified specification. To create a=C2= =A0sequence=C2=A0in=C2=A0PostgreSQL, you use the CREATE=C2=A0SEQUENCE=C2=A0statement.<= /p>

After a sequence is created, you use the=C2=A0

functions=C2=A0nextval,=C2=A0currval, and=C2=A0setval=C2=A0to operate on the sequence. These functions are documented in=C2= =A0Section 9.16.

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

SELECT * FROM name;


On Wed, 18 Dec 2019, 05:3= 3 Mike Dewhirst, <miked@dewhirst.com.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


--0000000000004f050a0599f50ce5--