From: | Ragnar Kjørstad <postgres(at)ragnark(dot)vestdata(dot)no> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | Rainer Mager <rmager(at)vgkk(dot)com>, pgsql-admin(at)postgresql(dot)org |
Subject: | Re: A few misc. questions. |
Date: | 2000-05-27 07:32:10 |
Message-ID: | 20000527093210.B29792@vestdata.no |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Fri, May 26, 2000 at 04:15:31PM +0200, Peter Eisentraut wrote:
> On Fri, 26 May 2000, Rainer Mager wrote:
>
> > 2. Does anyone one know a standard SQL method (that works with Postgres) to
> > retrieve the primary key of a newly INSERTed record? We've found one way but
> > it will not work with order databases since it relies on reading data from
> > the sequence tables.
>
> Again, what you do with your primary keys is up to you. Ideally you won't
> need to retrieve the primary key value because you know what you just
> inserted. If you are talking about serial, then the answer is there isn't
> one because serial isn't SQL. But as someone already said, the curval
> function will do.
Another approach is something like this:
pkey=sql("select nextval('some-sequence')")
sql("insert into table values ($pkey, $data)")
--
Ragnar Kjørstad
From | Date | Subject | |
---|---|---|---|
Next Message | Vladimir V. Zolotych | 2000-05-27 09:39:18 | password |
Previous Message | Norbert Meissner | 2000-05-26 18:00:51 | Re: Bug or Feature ? |