Received: from romana ([207.215.68.163]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f6K88Ka48191 for ; Fri, 20 Jul 2001 04:08:21 -0400 (EDT) (envelope-from hajhouse@houseag.com) Received: from hajhouse by romana with local (Exim 3.22 #1 (Debian)) id 15NUtt-0001Tn-00; Fri, 20 Jul 2001 00:40:41 -0700 Date: Fri, 20 Jul 2001 00:40:41 -0700 To: Dado Feigenblatt Cc: Pgsql-Sql Subject: Re: nextval on insert by arbitrary sequence Message-ID: <20010720004041.A5624@houseag.com> References: <3B5794B0.8060201@wildbrain.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline In-Reply-To: <3B5794B0.8060201@wildbrain.com> User-Agent: Mutt/1.3.18i From: Henry House X-Archive-Number: 200107/264 X-Sequence-Number: 4061 --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 19, 2001 at 07:17:20PM -0700, Dado Feigenblatt wrote: > I'm not sure if I worded the subject right, but my problem is this: >=20 > I have a few entries in one table. Each row is the parent of many=20 > entries in a second table. > In the second table I have a lot of entries referencing the entries on=20 > the first table. > So far so good. Basic foreign key thing. > The entries on the second table need to be numbered, but instead of a=20 > single sequence for all rows, > I need a sequence per group of rows, according to their parent record. >=20 > I have some ideas but they are not coming together. > I thought of creating individual sequences for each new parent row, and= =20 > maybe store its name in the parent row itself, so it can be accessed by= =20 > it's children row. > But then, how do I get a field on the second table to DEFAULT to=20 > nextval() on it's parent's sequence? I have done this manally, by creating a sequence and the grabbing a unique number from the sequence using 'SELECT nextval('seq_name'). I then use this number in all the INSERTs. Even though it takes one extra query, it is a simple approach and PostgreSQL guarantees that the sequence will return unique, sequential numbers as long as it is used consistently. --=20 Henry House OpenPGP key available from http://romana.hajhouse.org/hajhouse.asc --17pEHd4RhPHOinZp Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE7V+B4KK1cAVjXujwRAo1yAKC3Leiocvqcos6uEslxzd2p2/vzCQCghAza V/fOL3wVu49h9GwHiRlXN6c= =KL/D -----END PGP SIGNATURE----- --17pEHd4RhPHOinZp--