DO $d$
    BEGIN
        EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
            OPTIONS (dbname '$$||current_database()||$$',
                     port '$$||current_setting('port')||$$'
            )$$;
    END;
$d$;

CREATE USER MAPPING FOR CURRENT_USER SERVER loopback;

create table table_1 (a int);
create table table_2 (a int);


create foreign table remote_table_1 (a int) server loopback options (schema_name 'public', table_name 'table_1');
create foreign table remote_table_2 (a int) server loopback options (schema_name 'public', table_name 'table_2');

SELECT * FROM (SELECT 2023 AS year, * FROM remote_table_1 UNION ALL SELECT 2022 AS year, * FROM remote_table_2) ORDER BY year DESC;


