4 ms·
This problem can also be solved with SQL. An after trigger on the table and an indexed computed column would all work. If you're using Postgres probably just a
by fleitz 15y ago
This problem can also be solved with SQL. An after trigger on the table and an indexed computed column would all work. If you're using Postgres probably just a regular INSERT with a call to curval.
This seems like an awful lot of work to avoid a stored proc / trigger, computed columns, or custom INSERT statement. Even in MySQL a stored proc would work, or two INSERT statements in a transaction.
- jeltz 15y agoMinor correction: You call nextval in PostgreSQL to increment a sequence and get the number. curval is for getting the last value returned by a nextval call within the current transaction. Since PostgreSQL implemented RETURNING for INSERTs and UPDATEs curval has become more of a utility function for use with psql and similar clients.
- deleted 15y ago[deleted]