for loop

From: Pepe TD Vo <pepevo(at)yahoo(dot)com>
To: Pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: for loop
Date: 2018-11-07 18:34:11
Message-ID: 1261661192.463274.1541615651596@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

I have a script migrating from oracle to Postgres.  I have checked online and don't see anything wrong on for ... loop statement.  Would you please tell me what is wrong where?
CREATE OR REPLACE FUNCTION "CIDRDBA"."CIDRDBA_CONSTRAINTS" ( val in varchar(4000) ) RETURNS VOIDas $$begin        if val = 'DISABLE' then                raise notice '%', 'CIDRDBA Constarints are being disabled';                for c in ( select table_name, constraint_name from information_schema.table_constraints                        where constraint_type = 'R' )                loop                        raise notice '%', 'Processing table: ' || c.table_name || ' - constraint' || c.constraint_name;                        execute immediate 'alter table ' || c.table_name ||' ' || val || ' constraint ' ||                                c.constraint_name ;                end loop;                for c in ( select table_name, constraint_name from information_schema.table_constraints                        where constraint_type = 'P' )                loop                        raise notice '%', 'Processing table: ' || c.table_name || ' - constraint' || c.constraint_name;                        execute immediate 'alter table ' || c.table_name || ' ' || val || ' constraint ' ||                                c.constraint_name ;                end loop;        elsif val = 'ENABLE' then                raise notice '%', 'CIDRDBA Constarints are being enabled';                for c in ( select table_name, constraint_name from information_schema.table_constraints                        where constraint_type = 'P' )                loop                        raise notice '%', 'Processing table: ' || c.table_name || ' - constraint' || c.constraint_name;                        execute immediate 'alter table ' || c.table_name ||' ' || val || ' constraint ' ||                                c.constraint_name ;                end loop;                for c in ( select table_name, constraint_name from information_schema.table_constraints                        where constraint_type = 'R' )                loop                        raise notice '%', 'Processing table: ' || c.table_name || ' - constraint' || c.constraint_name;                        execute immediate 'alter table ' || c.table_name || ' ' || val || ' constraint ' ||                                c.constraint_name ;                end loop;        else                raise notice '%', 'CIDRDBA nothing to do';        end if;end;$$ LANGUAGE plpgsql;

ERROR:  loop variable of loop over rows must be a record or row variable or list of scalar variablesLINE 6:                 for c in ( select table_name, constraint_nam...                            ^SQL state: 42601Character: 238
 Bach-Nga

No one in this world is pure and perfect.  If you avoid people for their mistakes you will be alone. So judge less, love and forgive more.To call him a dog hardly seems to do him justice though in as much as he had four legs, a tail, and barked, I admit he was, to all outward appearances. But to those who knew him well, he was a perfect gentleman (Hermione Gingold)
**Live simply **Love generously **Care deeply **Speak kindly.*** Genuinely rich *** Faithful talent *** Sharing success

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Igor Neyman 2018-11-07 18:46:51 RE: for loop
Previous Message Pepe TD Vo 2018-11-07 15:10:25 query can't merge into table of the other schema