Re: Renaming sequences

Zahid Rahman <[email protected]> Wed, 18 Dec 2019 07:03:44 +0000
Newsgroups gmane.comp.db.postgresql.novice
Message-ID <CAPGSW3Tf6AzUZtaOt81C5EccV_vwDLx8CffWFxaQkAddtPq1TA@mail.gmail.com>
--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, <[email protected]> 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
> <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, <[email protected]> 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

<div dir=3D"auto"><div><span style=3D"font-family:sans-serif">&gt; The fact=
 that it is working with mismatched names .</span></div><div dir=3D"auto"><=
span style=3D"font-family:sans-serif"><br></span></div><div dir=3D"auto"><f=
ont face=3D"sans-serif">I just had a quick look at django. It is not someth=
ing I know of or use.</font></div><div dir=3D"auto"><font face=3D"sans-seri=
f">Just a front end framework using python language as far as I can see.</f=
ont></div><div dir=3D"auto"><font face=3D"sans-serif"><br></font></div><div=
 dir=3D"auto"><font face=3D"sans-serif">&gt;</font><span style=3D"font-fami=
ly:sans-serif">mismatched names</span></div><div dir=3D"auto"><br></div><di=
v dir=3D"auto">I suspect you have sequences with different names.</div><div=
 dir=3D"auto"><br></div><div dir=3D"auto">Use</div><div dir=3D"auto">Select=
 * from sequence_name_a;</div><div dir=3D"auto"><span style=3D"font-family:=
sans-serif">Select * from sequence_name_b;</span><br></div><div dir=3D"auto=
"><span style=3D"font-family:sans-serif"><br></span></div><div dir=3D"auto"=
><span style=3D"font-family:sans-serif">If you get error free results then =
that means you have sequences with different names.</span></div><div dir=3D=
"auto"><span style=3D"font-family:sans-serif"><br></span></div><div dir=3D"=
auto"><span style=3D"font-family:sans-serif">If I understand=C2=A0 what you=
 are to begin with.</span></div><div dir=3D"auto"><span style=3D"font-famil=
y:sans-serif"><br></span></div><div dir=3D"auto"><span style=3D"font-family=
:sans-serif"><br></span></div><div dir=3D"auto"><br></div><div dir=3D"auto"=
><font face=3D"sans-serif"><br></font><br><div class=3D"gmail_quote" dir=3D=
"auto"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, 18 Dec 2019, 06:23 Mik=
e Dewhirst, &lt;<a href=3D"mailto:[email protected]" rel=3D"noreferrer =
noreferrer noreferrer" target=3D"_blank">[email protected]</a>&gt; wrot=
e:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex">
 =20
   =20
 =20
  <div text=3D"#000000" bgcolor=3D"#FFFFFF">
    <div>On 18/12/2019 5:03 pm, Zahid Rahman
      wrote:<br>
    </div>
    <blockquote type=3D"cite">
     =20
      <div dir=3D"auto">
        <div>
          <p>If
            you are referring to a sequence which meets the same
            definition below. That is to say a persistent number
            generator.=C2=A0</p>
          <p>Surely
            by=C2=A0 changing=C2=A0 the sequence name then any=C2=A0 code u=
sing that
            sequence by name will fail. That&#39;s from an application
            developer&#39;s view.</p>
        </div>
      </div>
    </blockquote>
    <br>
    Yes. <br>
    <br>
    I think I&#39;d better ask on the Django users list. <br>
    <br>
    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.<br>
    <br>
    Thanks<br>
    <br>
    <br>
    <blockquote type=3D"cite">
      <div dir=3D"auto">
        <div>
          <p><br>
          </p>
          <p><span style=3D"color:rgb(60,64,67);font-family:roboto,helvetic=
aneue,arial,sans-serif;font-size:18px">A=C2=A0</span><b style=3D"max-height=
:999999px;color:rgb(60,64,67);font-family:roboto,helveticaneue,arial,sans-s=
erif;font-size:18px">sequence</b><span style=3D"color:rgb(60,64,67);font-fa=
mily:roboto,helveticaneue,arial,sans-serif;font-size:18px">=C2=A0in</span><=
b style=3D"max-height:999999px;color:rgb(60,64,67);font-family:roboto,helve=
ticaneue,arial,sans-serif;font-size:18px">PostgreSQL</b><span style=3D"colo=
r:rgb(60,64,67);font-family:roboto,helveticaneue,arial,sans-serif;font-size=
:18px">=C2=A0is
              a user-defined schema-bound object that generates a</span><b =
style=3D"max-height:999999px;color:rgb(60,64,67);font-family:roboto,helveti=
caneue,arial,sans-serif;font-size:18px">sequence</b><span style=3D"color:rg=
b(60,64,67);font-family:roboto,helveticaneue,arial,sans-serif;font-size:18p=
x">=C2=A0of
              integers based on a specified specification. To create a=C2=
=A0</span><b style=3D"max-height:999999px;color:rgb(60,64,67);font-family:r=
oboto,helveticaneue,arial,sans-serif;font-size:18px">sequence</b><span styl=
e=3D"color:rgb(60,64,67);font-family:roboto,helveticaneue,arial,sans-serif;=
font-size:18px">=C2=A0in=C2=A0</span><b style=3D"max-height:999999px;color:=
rgb(60,64,67);font-family:roboto,helveticaneue,arial,sans-serif;font-size:1=
8px">PostgreSQL</b><span style=3D"color:rgb(60,64,67);font-family:roboto,he=
lveticaneue,arial,sans-serif;font-size:18px">,
              you use the CREATE=C2=A0</span><b style=3D"max-height:999999p=
x;color:rgb(60,64,67);font-family:roboto,helveticaneue,arial,sans-serif;fon=
t-size:18px">SEQUENCE=C2=A0</b><span style=3D"color:rgb(60,64,67);font-fami=
ly:roboto,helveticaneue,arial,sans-serif;font-size:18px">statement.</span><=
/p>
          <p>After
            a sequence is created, you use the=C2=A0</p>
          <p>functions=C2=A0<code style=3D"font-family:monospace,monospace;=
font-size:1em;border-radius:0.25rem;margin:0.6rem 0px;color:inherit!importa=
nt;background-color:rgb(248,249,250)!important">nextval</code>,=C2=A0<code =
style=3D"font-family:monospace,monospace;font-size:1em;border-radius:0.25re=
m;margin:0.6rem 0px;color:inherit!important;background-color:rgb(248,249,25=
0)!important">currval</code>,
            and=C2=A0<code style=3D"font-family:monospace,monospace;font-si=
ze:1em;border-radius:0.25rem;margin:0.6rem 0px;color:inherit!important;back=
ground-color:rgb(248,249,250)!important">setval</code>=C2=A0to
            operate on the sequence. These functions are documented in=C2=
=A0<a href=3D"https://www.postgresql.org/docs/9.5/functions-sequence.html" =
style=3D"color:rgb(132,0,50);text-decoration-line:none;background-color:tra=
nsparent;font-weight:600" rel=3D"noreferrer noreferrer noreferrer noreferre=
r noreferrer noreferrer" target=3D"_blank">Section 9.16</a>.</p>
          <p>Although
            you cannot update a sequence directly, you can use a query
            like:</p>
          <pre style=3D"font-family:monospace,monospace;font-size:14.4px;co=
lor:rgb(13,10,11);border-radius:0.25rem;border:1px solid rgb(206,212,218);m=
argin-top:1rem!important;margin-bottom:1rem!important;background-color:rgb(=
248,249,250)!important;padding:0.8rem!important">SELECT * FROM <tt style=3D=
"font-weight:900;font-style:italic;border-radius:0.25rem;margin:0.6rem 0px;=
font-size:0.9rem!important;color:inherit!important">name</tt>;</pre>
          <br>
          <br>
          <div class=3D"gmail_quote">
            <div dir=3D"ltr" class=3D"gmail_attr">On Wed, 18 Dec 2019, 05:3=
3
              Mike Dewhirst, &lt;<a href=3D"mailto:[email protected]" r=
el=3D"noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" ta=
rget=3D"_blank">[email protected]</a>&gt;
              wrote:<br>
            </div>
            <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex">
              <div text=3D"#000000" bgcolor=3D"#FFFFFF"> <font size=3D"-1">=
Are
                  there any consequences for renaming sequences to match
                  the tables which own them?<br>
                  <br>
                  In an existing production Django project I have just
                  converted auth.user into common.user and
                  company.userprofile into common.userprofile.<br>
                  <br>
                  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
                  <a href=3D"http://public.common_user.id" rel=3D"noreferre=
r
                    noreferrer noreferrer noreferrer noreferrer noreferrer =
noreferrer" target=3D"_blank">public.common_user.id</a><br>
                  <br>
                  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.<br>
                  <br>
                  I know how I could do it but I just need to know if I
                  should.<br>
                  <br>
                  Thanks for any advice<br>
                  <br>
                  Mike<br>
                  <br>
                </font> </div>
            </blockquote>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </div>

</blockquote></div></div></div>

--0000000000004f050a0599f50ce5--