I am trying to create a new sequence in PostgreSQL with the start value being the max of all available ids in all the tables using the following query:
CREATE SEQUENCE idschema.global_id_sequence INCREMENT 1 START (
SELECT MAX(t.max_id) FROM
(
(SELECT MAX(public.tbl1.id) max_id FROM public.tbl1) UNION
(SELECT MAX(public.tbl2.id) max_id FROM public.tbl2) UNION
(SELECT MAX(public.tbl3.id) max_id FROM public.tbl2) UNION
) t
);
This doesn't seem to work. How can I achieve the above in PostgreSQL using scalars or other means?