I want to be able to use the current value of an auto ID by giving it some kind of name and just referring to it (instead of calling SELECT for each record):
Requests table has a serial column named requestid
.
insert into testschema.requests (chid) values
(1);
I want to use select currval()
multiple times without having to use SELECT for each line:
insert into testschema.requestinfo (requestid, reportid, amount) values
((select currval('testschema.requests_requestid_seq')), 10, 40),
((select currval('testschema.requests_requestid_seq')), 15, 29),
((select currval('testschema.requests_requestid_seq')), 40, 4);
I've tried placing the select on its own line with no success:
SELECT currval('testschema.requests_requestid_seq') as reqid;
INSERT INTO testschema.requestinfo(requestid, reportid) VALUES
(reqid, 2);
Bottom line: I want to refer to the currval without having to use SELECT currval()
for each line.