the situation. I'm producing a function, and part of it needs to get the name of each table by concatenating schemaname.tablename to iterate. part of the code:
the part that it´s producing the error:
select schemaname||'.'||tablename as otra from pg_tables where schemaname = 'vigano' and pg_tables.tablename ~ 'ver1920_soja_filtrado$'
The hole function is this one:
CREATE OR REPLACE FUNCTION yield_summary()
RETURNS TABLE (
promedio double precision,
minimo double precision,
maximo double precision
) LANGUAGE plpgsql AS
$$DECLARE
v_sql text := '';
v_sep text := '';
v_tab text;
BEGIN
FOR v_tab IN
select schemaname||'.'||tablename as otra from pg_tables where schemaname = 'vigano' and pg_tables.tablename ~ 'ver1920_soja_filtrado$'
LOOP
v_sql := v_sql || v_sep ||
format(
'select round(avg(masa_de_re)::numeric,3) as promedio, round(min(masa_de_re)::numeric,3) as minimo, round(max(masa_de_re)::numeric,3) as maximo
FROM %I',
v_tab
);
v_sep := ' UNION ALL ';
END LOOP;
RETURN QUERY EXECUTE v_sql;
END;$$;
it produces the right table schemaname.tablename, but..it doesn't recognize it because of the double quotes.
ERROR: no existe la relación «vigano.elcerro_elmolino_ver1920_soja_filtrado»
LINE 2: FROM "vigano.elcerro_elmolino_ver1920_soja_filtrado" UNI...
^
how do I get rid of the double quotes??
if i use quote_indent()
select quote_ident(schemaname||'.'||tablename) as otra from pg_tables where schemaname = 'vigano' and pg_tables.tablename ~ 'ver1920_soja_filtrado$'
it produces this:
ERROR: no existe la relación «"vigano.elcerro_elmolino_ver1920_soja_filtrado"»
LINE 2: FROM """vigano.elcerro_elmolino_ver1920_soja_filtrado""" ^
If I use quote_literal()
select quote_literal(schemaname||'.'||tablename) as otra from pg_tables where schemaname = 'vigano' and pg_tables.tablename ~ 'ver1920_soja_filtrado$'
it produces:
ERROR: no existe la relación «'vigano.elcerro_elmolino_ver1920_soja_filtrado'»
LINE 2: FROM "'vigano.elcerro_elmolino_ver1920_soja_filtrado'" U...
^
thanks