You can't do that in one command, you need first to execute one to build the SELECT statement you want, and the copy its result and execute it:
SELECT string_agg(
format('(SELECT * FROM %I.ref_product)', nspname),
' UNION ALL ')
FROM pg_namespace
WHERE nspname !~ '^(pg_.*|information_schema|public)$';
Another option is to use PL/pgSQL EXECUTE command, for example:
CREATE OR REPLACE FUNCTION ref_product()
RETURNS SETOF tenant1.ref_product
LANGUAGE plpgsql STABLE AS $$
DECLARE
v_cmd text;
BEGIN
SELECT string_agg(
format('(SELECT * FROM %I.ref_product)', nspname),
' UNION ALL ')
INTO v_cmd
FROM pg_namespace
WHERE nspname !~ '^(pg_.*|information_schema|public)$'
RETURN QUERY EXECUTE v_cmd;
END;
$$;
At last, if you are using this often, consider create another schema (let's say "tenant_all") with the same table definition, and set all other table as child of it using PostgreSQL's INHERTIS. For example:
CREATE SCHEMA tenant_all;
CREATE TABLE tenant_all.ref_product(LIKE tenant1.ref_product);
ALTER TABLE tenant1.ref_product INHERIT (tenant_all.ref_product);
ALTER TABLE tenant2.ref_product INHERIT (tenant_all.ref_product);
ALTER TABLE tenant3.ref_product INHERIT (tenant_all.ref_product);
...
ALTER TABLE tenantN.ref_product INHERIT (tenant_all.ref_product);
So that way you can simple query tennat_all.ref_product and it will work exactly as if you are querying it one appended with UNION ALL.
Of course in all cases I'm assuming the tables schema matches perfectly.
table_schemawill returnstenant1,tenant2,tenant3,right ??ref_product's structure(create script) ???ref_product