Received: from flip.wildbrain.com ([206.54.55.32]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f6KHF1a06191 for ; Fri, 20 Jul 2001 13:15:01 -0400 (EDT) (envelope-from dado@wildbrain.com) Received: from wildbrain.com (daedelus.wildbrain.com [192.168.1.38]) by flip.wildbrain.com (8.9.3/8.9.3) with ESMTP id JAA05595; Fri, 20 Jul 2001 09:12:44 -0700 Message-ID: <3B5866A0.6060503@wildbrain.com> Date: Fri, 20 Jul 2001 10:13:04 -0700 From: Dado Feigenblatt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010628 X-Accept-Language: en-us MIME-Version: 1.0 To: hajhouse@houseag.com CC: Pgsql-Sql Subject: Re: nextval on insert by arbitrary sequence References: <3B5794B0.8060201@wildbrain.com> <20010720004041.A5624@houseag.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200107/281 X-Sequence-Number: 4084 Henry House wrote: >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: >> >>I have a few entries in one table. Each row is the parent of many >>entries in a second table. >>In the second table I have a lot of entries referencing the entries on >>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 >>single sequence for all rows, >>I need a sequence per group of rows, according to their parent record. >> >>I have some ideas but they are not coming together. >>I thought of creating individual sequences for each new parent row, and >>maybe store its name in the parent row itself, so it can be accessed by >>it's children row. >>But then, how do I get a field on the second table to DEFAULT to >>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. > You kind of implied the answer to my question. You just does it in the client instead of using back stored functions/triggers or contrived SQL to handle that, right? Thanks -- Dado Feigenblatt Wild Brain, Inc. Technical Director (415) 553-8000 x??? dado@wildbrain.com San Francisco, CA.