Home > front end >  type sql_identifier does not exis
type sql_identifier does not exis

Time:05-21

So I am trying to run this function

CREATE OR REPLACE FUNCTION TableIteration() 
  RETURNS TABLE(table_schema text, table_name text)
  LANGUAGE plpgsql
AS
$$
DECLARE 
    tgt_schema varchar;
    list varchar[] := ARRAY[
    'sometext1',
    'sometext2',
    'sometext3',
    'sometext4',
    'sometext5',
    'sometext6',
    'sometext7',
    'sometext8',
    'sometext9'
];
BEGIN
    FOREACH tgt_schema IN ARRAY list
        LOOP
        RETURN QUERY EXECUTE
        'SELECT t.table_schema, t.table_name from information_schema.tables t'; 
        END LOOP;
    END
$$ 

And I am getting

ERROR: structure of query does not match function result type
Detail: Returned type information_schema.sql_identifier does not match expected type text in column 1.

But if I change types to sql_identifier I can't create function because it says that there's no such type. So the question is what should i do?

CodePudding user response:

The information schema columns have a strange data type (which - I think - is mandated by the SQL standard). Just cast them to text:

'SELECT t.table_schema::text, t.table_name::text from information_schema.tables t'; 
  • Related