INSERT, UPDATE and DELETE in PostgreSQL have a RETURNING clause which means you can do:
INSERT INTO ....
RETURNING id;
Then the query will return the value it inserted for id for each row inserted. Saves a roundtrip to the server.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…