Re: Nocount and scope_identity() - Mailing list pgsql-sql

From Andrew Sullivan
Subject Re: Nocount and scope_identity()
Date
Msg-id 20070202195729.GJ11505@phlogiston.dyndns.org
Whole thread Raw
In response to Re: Nocount and scope_identity()  ("Demel, Jeff" <Jeff.Demel@JavelinDirect.com>)
Responses Re: Nocount and scope_identity()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: "Karthikeyan Sundaram"
Date:
Subject: Question regarding multibyte.
Next
From: Tom Lane
Date:
Subject: Re: Nocount and scope_identity()