I want to unite the following two queries into one:
SELECT pg_get_serial_sequence('purchase_orders', 'id');
SELECT setval('purchase_orders_id_seq', 30000);
But if I place the upper SELECT into the setval's first parameter I get:
SELECT setval(SELECT pg_get_serial_sequence('purchase_orders', 'id'), 30000);
ERROR: syntax error at or near "SELECT"
SQL state: 42601
Character: 15
How can I pass on the select's result ("purchase_orders_id_seq") for setval?
EDIT: The reason for this is that; I want to use it like a function where a user only have to enter the table's name and a number to where sequence will be set.
FUNCTION set_id_sequence(TEXT table_name, INTEGER sequence);
pg_serial_get_sequence? I've never heard of it, and my 9.4 install professes ignorance when asked with\df pg_get_serial_sequence. What're you trying to accomplish/fix here, what problem are you trying to solve?