Syntax checking DO blocks and ALTER TABLE statements?

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Syntax checking DO blocks and ALTER TABLE statements?
Date: 2021-02-16 22:42:56
Message-ID: ef0b6d3f-e351-2aef-b09d-3f817cf83269@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


How does one go about syntax checking this?

do $$
begin if exists (select 1 from information_schema.table_constraints
       where constraint_name = 'error_to_web_service_error') then
            raise notice 'EXISTS error_to_web_service_error';
    else
        ALTER TABLE web_service_error
           ADD CONSTRAINT error_to_web_service_error FOREIGN KEY (error_id)
           REFERENCES error_code(error_id)
           ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;
    end if
end $$

(There are 222 ALTER TABLE ADD FOREIGN KEY statements that I'm wrapping in
similar DO blocks, and want to make sure the statements are clean.)

--
Angular momentum makes the world go 'round.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-02-16 23:11:14 Re: Syntax checking DO blocks and ALTER TABLE statements?
Previous Message Ron 2021-02-16 22:11:02 Re: Order by not working