DO $$
DECLARE
r RECORD;
BEGIN
-- Select all primary key constraints in the 'public' schema
FOR r IN (
SELECT
table_name,
constraint_name
FROM
information_schema.table_constraints
WHERE
constraint_type = 'PRIMARY KEY' AND
table_schema = 'public'
)
LOOP
-- Execute the ALTER TABLE DROP CONSTRAINT command for each primary key
EXECUTE 'ALTER TABLE ' || quote_ident(r.table_name) || ' DROP CONSTRAINT ' || quote_ident(r.constraint_name) || ' CASCADE';
END LOOP;
END $$;