Using common numeric id across multiple tables

create sequence seq;
CREATE VIEW seq_view AS SELECT nextval(‘seq’) as a;
CREATE EXTENSION postgres_fdw;CREATE SERVER global_seq FOREIGN DATA WRAPPER postgres_fdw OPTIONS(host ‘192.168.XX.XX’, port ‘5432’, dbname ‘mydatabase’);CREATE USER MAPPING FOR PUBLIC SERVER global_seq OPTIONS (user ‘User’ , password ‘xxxx’);CREATE FOREIGN TABLE seqtable (a bigint) SERVER global_seq OPTIONS (table_name ‘seq_view’);
CREATE OR REPLACE FUNCTION public.func()
RETURNS bigint
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$
declare b bigint;
BEGIN
b := (select * from seqtable);
RETURN b;
end;
$function$;
Create table mytab(col1 int8 not null default func(),col2 int2);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store