I'm trying to migrate the next function into PostgreSQL:
CREATE OR REPLACE FUNCTION mar.change_const (command text) RETURNS
VOID AS $body$
DECLARE
C_Procedure_Name CONSTANT varchar(30) := 'change_constraints';
V_Step real := 0;
/* command values: ENABLE | DISABLE */
all_constraints CURSOR(stat text) FOR
SELECT *
FROM all_constraints
WHERE status = stat;
cons all_constraints%ROWTYPE;
line varchar(200);
cons_status varchar(10);
BEGIN
RAISE NOTICE 'Start : %, %', C_Procedure_Name, TO_CHAR(clock_timestamp());
V_Step := 1;
IF command IN ('enable', 'ENABLE') THEN
cons_status := 'DISABLED';
ELSE
cons_status := 'ENABLED';
END IF;
V_Step := 2;
FOR cons IN all_constraints(cons_status)
LOOP
V_Step := 2.1;
line := 'alter table ' || cons.table_name || ' ' || command ||
' novalidate constraint ' || CONS.CONSTRAINT_NAME;
V_Step := 2.2;
EXECUTE line;
END LOOP;
I know that I can switch all_constraints with information_schema.table_constraints but how can I change the other parts of the code ? I can't disable and enable constraints in PostgreSQL and I don't want to drop them in this part.
I read that I can alter the check constraints (which are the only type of constraint that I have) to novalidate but I didn't find any example in a search engine.