sqlpostgresqlfunctionstored-proceduresamazon-redshift

Language plpgsql not supported for CREATE FUNCTION


I have created a function in redshift. But it is throwing an error of language plpgsql not supported for create function. How do I resolve this?

Expected other languages but didn't work. Also I tried to review the logic if it fits as per my requirement which I believe is correct.

Create or Replace Function update_tablename_tablecounts(c_date TEXT)
Returns void 
volatile
AS $$ language plpgsql
Declare
    table_name TEXT;
    row_count INT;
Begin
Create temp table temp_table (
        table_name TEXT unique,
        row_count INT
);

For table_name in Select table_name 
From information_schema.tables
Where table_schema = 'MMO_MMO_proc_'||c_date||'' 
And table_name in ('elig_59_v02', 'prvtonet_6_v03', 'prvtonet_6_v03_pass0','prvtonet_6_v03_pass1','prvtonet_6_v03_final','roster_final') 
Loop
Execute 'SELECT COUNT(*) FROM ' || table_name INTO row_count;
Insert Into temp_table (table_name, row_count)
Values (table_schema.table_name, row_count);
End Loop;
   
Create table if not exists table_counter (
        table_name TEXT,
        row_count INT
);
    
Insert into table_counter
Select * from temp_table;

Drop table temp_table;
 

End;
$$ language plpgsql;

Solution

  • Are you sure it doesn't just support procedures in pl/pgsql?

    https://docs.aws.amazon.com/redshift/latest/dg/c_PLpgSQL-structure.html

    https://docs.aws.amazon.com/redshift/latest/dg/user-defined-functions.html