Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 2DAF22E0046 for ; Thu, 22 Nov 2007 07:11:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 55717-10 for ; Thu, 22 Nov 2007 07:11:25 -0400 (AST) Received: from interscan.indicator.com (mail.indicator.be [193.121.199.3]) by postgresql.org (Postfix) with ESMTP id C09C72E003D for ; Thu, 22 Nov 2007 07:11:28 -0400 (AST) Received: from webaccess.indicator.be ([10.100.1.7]) by interscan.indicator.com with InterScan Message Security Suite; Thu, 22 Nov 2007 12:09:02 +0100 Received: from DOMEXT-MTA by webaccess.indicator.bewith Novell_GroupWise; Thu, 22 Nov 2007 12:11:25 +0100 Message-Id: <474571E8.A3DD.0030.0@indicator.be> X-Mailer: Novell GroupWise Internet Agent 7.0.1 Date: Thu, 22 Nov 2007 12:11:20 +0100 From: "Bart Degryse" To: Subject: Re: How to have a unique primary key on two tables References: <99d8c2310711220301p57c9b7c5i4620a7e658d13b7d@mail.gmail.com> In-Reply-To: <99d8c2310711220301p57c9b7c5i4620a7e658d13b7d@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=__PartC1E7CEC8.0__=" X-imss-version: 2.049 X-imss-result: Passed X-imss-approveListMatch: *@indicator.be X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/111 X-Sequence-Number: 29639 --=__PartC1E7CEC8.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable When you use serial a kind of macro is performed: in fact an integer field = is created, a sequence is created with a name based on the table's name = and the nextval of that sequence is used as the default value for the = field. Now you have to do these steps "manually". =20 CREATE SEQUENCE "public"."tbl_all_ID_seq" INCREMENT 1 MINVALUE 1 START 1 = CACHE 1; =20 CREATE TABLE tbl_first ( id INTEGER DEFAULT nextval('public."tbl_all_ID_seq"'::text) NOT NULL,=20 testo text ); CREATE TABLE tbl_second ( id INTEGER DEFAULT nextval('public."tbl_all_ID_seq"'::text) NOT NULL,=20 testo text ); >>> "Daniel "bodom_lx" Graziotin" 2007-11-22 = 12:01 >>> Hi everybody, I need to have a primary key which has to be unique on two tables. E.g.: CREATE TABLE first ( id serial NOT NULL, testo text, ) CREATE TABLE second ( id serial NOT NULL, testo text, ) When I insert some text on "first", I would like first.id =3D second.id + 1, and vice versa. A sort of primary key in common for both tables. Any hints? Thank you very much --=20 Daniel "bodom_lx" Graziotin - http://daniel.graziotin.net ( http://daniel.graziotin.net/ ) - http://daniel.graziotin.net/bodom_lx.asc - GPG public key ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq --=__PartC1E7CEC8.0__= Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Description: HTML
When you use serial a kind of macro is performed: in fact an integer = field is created, a sequence is created with a name based on the = table's name and the nextval of that sequence is used as the default value = for the field. Now you have to do these steps "manually".
 
CREATE SEQUENCE "public"."tbl_all_ID_seq" INCREMENT 1 MINVALUE 1 = START 1 CACHE 1;
 
CREATE TABLE tbl_first (
  id INTEGER DEFAULT = nextval('public."tbl_all_ID_seq"'::text) NOT NULL, 
  testo = text
);

CREATE TABLE tbl_second (
  id INTEGER = DEFAULT nextval('public."tbl_all_ID_seq"'::text) NOT NULL, 
  = testo text
);
>>> "Daniel "bodom_lx" Graziotin" <daniel.graziotin@gmail.= com> 2007-11-22 12:01 >>>
Hi everybody,
I need to have a = primary key which has to be unique on two tables.
E.g.:

CREATE = TABLE first
(
  id serial NOT NULL,
  testo text,
)
CREATE TABLE second
(
  id serial NOT NULL,
  = testo text,
)

When I insert some text on "first", I would like = first.id =3D second.id
+ 1, and vice versa.
A sort of primary key in = common for both tables.

Any hints?
Thank you very much
-- =
Daniel "bodom_lx" Graziotin
- http://daniel.graziotin.net
- http://daniel.graziotin.net/bodom_lx.asc - GPG = public key

---------------------------(end of broadcast)------------= ---------------
TIP 3: Have you checked our extensive FAQ?

 =             &nb= sp; http://www.postgresql.or= g/docs/faq
--=__PartC1E7CEC8.0__=--