Re: Best way to create unique primary keys across schemas? - Mailing list pgsql-general

From Chris Angelico
Subject Re: Best way to create unique primary keys across schemas?
Date
Msg-id CAPTjJmqD992Ey5uoVa-e+c67ZP_VT_GUX+4+_zYP7Ex1-UrsCQ@mail.gmail.com
Whole thread Raw
In response to Re: Best way to create unique primary keys across schemas?  (panam <panam@gmx.net>)
Responses Re: Best way to create unique primary keys across schemas?
List pgsql-general
On Thu, Jan 26, 2012 at 2:12 AM, panam <panam@gmx.net> wrote:
> CREATE TABLE tbl (ID bigint default nextval('global_seq') primary key,foo
> varchar,bar varchar);  --in public schema
> CREATE TABLE schema1.tbl (LIKE public.tbl INCLUDING ALL);  --draws ids from
> sequence in public schema
> CREATE TABLE schema2.tbl (LIKE public.tbl INCLUDING ALL);  --draws ids from
> sequence in public schema

Yep, but you can do this more simply:

CREATE TABLE schema1.tbl (ID bigint default nextval('global_seq')
primary key,foo varchar,bar varchar)
CREATE TABLE schema2.tbl (ID bigint default nextval('global_seq')
primary key,foo varchar,bar varchar)

No need for the dummy table.

Obviously you would want better names than these ("global_seq" is a
really dumb name for a production environment!), but you knew that
already :)

ChrisA

pgsql-general by date:

Previous
From: Leguevaques Alex
Date:
Subject: Composite Type : pros and cons
Next
From: salah jubeh
Date:
Subject: How to push predicate down