Re: sequences not renamed with tables

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: cool_screen_name90001(at)yahoo(dot)com
Subject: Re: sequences not renamed with tables
Date: 2003-12-18 02:36:29
Message-ID: 2e7bc154d174560c2614258f65b00e6e@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> I renamed a couple tables, and the names of their
> corresponding sequences remained the same. This causes
> a problem because when importing - the create table
> statements create sequences with different names, then
> the setval() statements use the old names. Any way to
> automatically avoid this "gotcha"?

Don't rely on the create table to make the sequences for
you: declare them yourself. Instead of this:

CREATE TABLE foobar (
id SERIAL
);

Try this:

CREATE SEQUENCE barbell_seq;

CREATE TABLE foobar (
id INTEGER NOT NULL DEFAULT nextval('barbell_seq')
);

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200312172134

-----BEGIN PGP SIGNATURE-----

iD8DBQE/4RJjvJuQZxSWSsgRAgEdAJ9y4eDaQENuRWVRETJdLu/vKO5PggCeKLjs
dkPyceUBRMkTbvcqMBAgLr4=
=5b5j
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Ganainm 2003-12-18 03:53:04 Re: Firebird and PostgreSQL at the DB Corral.
Previous Message Alice Bag 2003-12-18 01:59:02 Re: Firebird and PostgreSQL at the DB Corral.