> 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;
> >
> > If your table has a trigger that inserts into another table with its own
> > sequence, you're screwed.
>
> I assume you're equally screwed with MySQL LAST_INSERT_ID() in that case
> - so it'd be bug compatible.
Yeah, which is another reason not to use triggers; more pileups for the
whole "new features are there just for checklist's sake" argument.
The approach proposed by Alexander above does not have such problem,
which is why it is better than the alternative suggested by Russ.
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
No comments:
Post a Comment