Re: Best way to create unique primary keys across schemas?

From: Chris Angelico <rosuav(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Best way to create unique primary keys across schemas?
Date: 2012-01-26 11:56:09
Message-ID: CAPTjJmqD992Ey5uoVa-e+c67ZP_VT_GUX+4+_zYP7Ex1-UrsCQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jan 26, 2012 at 2:12 AM, panam <panam(at)gmx(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message salah jubeh 2012-01-26 13:51:18 How to push predicate down
Previous Message Sebastian Tennant 2012-01-26 11:54:44 Help needed creating a view