Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id C31BC2E003E for ; Thu, 22 Nov 2007 07:20:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 09875-08 for ; Thu, 22 Nov 2007 07:20:03 -0400 (AST) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by postgresql.org (Postfix) with ESMTP id 202232E0032 for ; Thu, 22 Nov 2007 07:20:03 -0400 (AST) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mrelayeu7) with ESMTP (Nemesis) id 0ML2xA-1IvA6C0FOl-00081B; Thu, 22 Nov 2007 12:20:01 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1IvA68-0003Bk-00 for pgsql-sql@postgresql.org; Thu, 22 Nov 2007 12:19:56 +0100 Date: Thu, 22 Nov 2007 12:19:56 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: How to have a unique primary key on two tables Message-ID: <20071122111956.GD2702@a-kretschmer.de> References: <99d8c2310711220301p57c9b7c5i4620a7e658d13b7d@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <99d8c2310711220301p57c9b7c5i4620a7e658d13b7d@mail.gmail.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1/m8J9As555/QegIE0UTCSnciedaxnLMMQtwy0 GFDc7s3W8XRy48V5CO4f8jLb77YsjMto10e49PO6120IpHytT9 wsPeInJcVsFng4hESRbYG2hsZS6JmP8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/112 X-Sequence-Number: 29640 am Thu, dem 22.11.2007, um 12:01:59 +0100 mailte Daniel bodom_lx Graziotin folgendes: > 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 = second.id > + 1, and vice versa. > A sort of primary key in common for both tables. > > Any hints? Yes. Create a SEQUENCE and use nextval(sequence) as primary key on both tables. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net