From: Andrew Sullivan <ajs@crankycanuck.ca>
To: pgsql-sql@postgresql.org
Subject: Re: Nocount and scope_identity()
Date: Fri, 2 Feb 2007 14:57:29 -0500
Message-ID: <20070202195729.GJ11505@phlogiston.dyndns.org> (raw)
In-Reply-To: <136ED738BD4F1545B97E4AC06FF6370734C25C@DMSP-MSG-EVS01.mail.pvt>
References: <136ED738BD4F1545B97E4AC06FF6370734C25C@DMSP-MSG-EVS01.mail.pvt>
On Fri, Feb 02, 2007 at 01:38:40PM -0600, Demel, Jeff wrote:
> Not as far as I know. What's it supposed to do?
>
> It suppresses the rowcount returned after the query runs.
There isn't a way to do that, although there is a way in psql, for
example, not to get all that formatting. You want the \pset
commands. The count isn't automatically delivered with most APIs
(i.e. if you want to know how many rows you touched, you usually have
to ask explicitly).
> > SCOPE_IDENTITY() method is going to work or not.
> I doubt it. What does it do?
>
> It returns the id of the record just inserted.
Ah. Well, there's no in-principle notion if "id" in Postgres (OIDs
are optional as of several versions ago). But if you have a primary
key that's an integer you populate using a sequence, then you can use
the currval() function to get the value of the sequence. There's no
race condition there unless you are sharing a pooled connection (and
if transactions mean anything to you, you'd better not be doing).
A
--
Andrew Sullivan | ajs@crankycanuck.ca
The fact that technology doesn't work is no bar to success in the marketplace.
--Philip Greenspun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ajs@crankycanuck.ca
Subject: Re: Nocount and scope_identity()
In-Reply-To: <20070202195729.GJ11505@phlogiston.dyndns.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox