There's an awesome feature that was added to PostgreSQL a while back
called RETURNING that allows you to make an INSERT, UPDATE, and DELETE
statement behave like a SELECT statement. You can do something like this:
INSERT INTO mytable (id, value)
VALUES (1, 'something')
RETURNING any_column_you_want;
This would be equivalent to running something like this in MySQL:
INSERT INTO mytable (id, value)
VALUES (1, 'something');
SELECT any_column_you_want
FROM mytable
WHERE id = 1;
Here is another example with an UPDATE query:
UPDATE mytable SET
value = 'something'
WHERE id = 1
RETURNING id, other_number;
The nice thing about this is that every insert or update can return any
column you want (even multiple columns) without having to do the
INSERT/UPDATE then turn around and perform another SELECT query.
I want to use this because when I insert a value into a table, I don't
always want to get the primary key returned to me. Sometimes I want
another column which may contain a candidate key and I'd like to avoid
the round-trip and additional logic incurred with running multiple queries.
Does RETURNING exist in any current release of MySQL or is it on the
TODO list even? If it's not, how can I go about asking to have it put
on there?
-- Dante
----------
D. Dante Lorenso
[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]