--- On Thu, 8/28/08, Masis, Alexander (US SSA) [EMAIL PROTECTED] wrote:
From: Masis, Alexander (US SSA) [EMAIL PROTECTED]
Subject: [GENERAL] MySQL LAST_INSERT_ID() to Postgres
To: pgsql-general@postgresql.org
Date: Thursday, August 28, 2008, 4:14 PM
I was mapping C++ application code
Alvaro Herrera wrote:
Russ Brown escribió:
Masis, Alexander (US SSA) wrote:
SELECT CURRVAL(
pg_get_serial_sequence('my_tbl_name','id_col_name'));
Any reason why you can't just do this?
CREATE FUNCTION last_insert_id() RETURNS bigint AS $$
SELECT lastval();
$$ LANGUAGE SQL VOLATILE;
Magnus Hagander escribió:
Alvaro Herrera wrote:
Russ Brown escribió:
Masis, Alexander (US SSA) wrote:
SELECT CURRVAL(
pg_get_serial_sequence('my_tbl_name','id_col_name'));
Any reason why you can't just do this?
CREATE FUNCTION last_insert_id() RETURNS bigint AS $$
SELECT
On 29/08/2008 05:45, Tom Lane wrote:
A general comment on those pages is that the tabular lists of functions
are intended to give one-liner descriptions of what the functions do.
For cases where a one-liner isn't sufficient, there's a sentence or a
paragraph following the table.
I don't
I was mapping C++ application code that works with mySQL to work with
Postgres.
There were a number of articles on line regarding the conversion from
mySQL to Postgres like:
http://en.wikibooks.org/wiki/Programming:Converting_MySQL_to_PostgreSQL
http://groups.drupal.org/node/4680
On Thu, Aug 28, 2008 at 10:14 AM, Masis, Alexander (US SSA)
[EMAIL PROTECTED] wrote:
I was mapping C++ application code that works with mySQL to work with
Postgres.
There were a number of articles on line regarding the conversion from
mySQL to Postgres like:
SNIP
Well, in MySQL it's easy you
Masis, Alexander (US SSA) wrote:
SELECT CURRVAL(
pg_get_serial_sequence('my_tbl_name','id_col_name'));
Any reason why you can't just do this?
CREATE FUNCTION last_insert_id() RETURNS bigint AS $$
SELECT lastval();
$$ LANGUAGE SQL VOLATILE;
--
Sent via pgsql-general mailing list
On Aug 28, 2008, at 12:09 PM, Scott Marlowe wrote:
On Thu, Aug 28, 2008 at 10:14 AM, Masis, Alexander (US SSA)
[EMAIL PROTECTED] wrote:
I was mapping C++ application code that works with mySQL to work with
Postgres.
There were a number of articles on line regarding the conversion from
mySQL
On Thu, Aug 28, 2008 at 1:56 PM, Steve Atkins [EMAIL PROTECTED] wrote:
Or lastval() if you want something bug-compatible with MySQL.
Not exactly. LAST_INSERT_ID is transactionally safe in that one
connection doesn't see another connections. However, it has it's own
special brand of bug that
Masis, Alexander (US SSA) wrote:
I was mapping C++ application code that works with mySQL to work with
Postgres.
There were a number of articles on line regarding the conversion from
mySQL to Postgres like:
http://en.wikibooks.org/wiki/Programming:Converting_MySQL_to_PostgreSQL
On 28/08/2008 22:26, Bill wrote:
someone confirm that currval() returns the the value for the connection
from which it is called?
Yes, see here:
http://www.postgresql.org/docs/8.3/static/functions-sequence.html
and specifically a little further down the page on currval:
Return the value
Steve Atkins wrote:
On Aug 28, 2008, at 12:09 PM, Scott Marlowe wrote:
On Thu, Aug 28, 2008 at 10:14 AM, Masis, Alexander (US SSA)
[EMAIL PROTECTED] wrote:
I was mapping C++ application code that works with mySQL to work with
Postgres.
There were a number of articles on line regarding the
On Thu, Aug 28, 2008 at 3:38 PM, Bill [EMAIL PROTECTED] wrote:
I am new to PostgreSQL but it seems to me that lastval() will only work if
the insert does not produce side effects that call nextval(). Consider the
case where a row is inserted into a table that has an after insert trigger
and
On Thu, 28 Aug 2008 16:06:14 -0600
Scott Marlowe [EMAIL PROTECTED] wrote:
On Thu, Aug 28, 2008 at 3:38 PM, Bill [EMAIL PROTECTED] wrote:
I am new to PostgreSQL but it seems to me that lastval() will only
work if the insert does not produce side effects that call
nextval(). Consider the
Russ Brown escribió:
Masis, Alexander (US SSA) wrote:
SELECT CURRVAL(
pg_get_serial_sequence('my_tbl_name','id_col_name'));
Any reason why you can't just do this?
CREATE FUNCTION last_insert_id() RETURNS bigint AS $$
SELECT lastval();
$$ LANGUAGE SQL VOLATILE;
If your table
Scott Marlowe wrote:
On Thu, Aug 28, 2008 at 3:38 PM, Bill [EMAIL PROTECTED] wrote:
I am new to PostgreSQL but it seems to me that lastval() will only work if
the insert does not produce side effects that call nextval(). Consider the
case where a row is inserted into a table that has an after
On Aug 28, 2008, at 3:23 PM, D. Dante Lorenso wrote:
I use RETURNING for all my insert and UPDATE statements now.
Usually I'll return the primary key for the table, but sometimes I
return a column that is created by one of my triggers. It's
awesome to be able to do this in one query.
Scott Marlowe wrote:
On Thu, Aug 28, 2008 at 3:38 PM, Bill [EMAIL PROTECTED] wrote:
I am new to PostgreSQL but it seems to me that lastval() will only work if
the insert does not produce side effects that call nextval(). Consider the
case where a row is inserted into a table that has an
On Thu, 28 Aug 2008 15:29:51 -0700
Bill [EMAIL PROTECTED] wrote:
The PostgresSQL 8.3 help file clearly shows that lastval() does not
take a sequence as a parameter and the description i is Return the
value most recently returned by |nextval| in the current session.
This function is identical
On Thu, Aug 28, 2008 at 4:18 PM, Joshua Drake [EMAIL PROTECTED] wrote:
On Thu, 28 Aug 2008 16:06:14 -0600
Scott Marlowe [EMAIL PROTECTED] wrote:
No, setval, currval, and lastval all require as an argument a sequence
name. So the real issue is you have to know the sequence name to use
them.
On Thu, 28 Aug 2008 16:46:19 -0600
Scott Marlowe [EMAIL PROTECTED] wrote:
On Thu, Aug 28, 2008 at 4:18 PM, Joshua Drake [EMAIL PROTECTED]
wrote:
On Thu, 28 Aug 2008 16:06:14 -0600
Scott Marlowe [EMAIL PROTECTED] wrote:
No, setval, currval, and lastval all require as an argument a
Raymond O'Donnell [EMAIL PROTECTED] writes:
On 28/08/2008 22:26, Bill wrote:
someone confirm that currval() returns the the value for the connection
from which it is called?
Yes, see here:
http://www.postgresql.org/docs/8.3/static/functions-sequence.html
and specifically a little further
22 matches
Mail list logo