Check constraints.

From: Steve Rogerson <steve(dot)pg(at)yewtc(dot)demon(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Check constraints.
Date: 2018-03-27 11:23:42
Message-ID: a6c7c35e-07d5-6a6c-0d60-5e3c0b439003@yewtc.demon.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

williamI am trying to add/change a constraint programmatically, but not if it
already exists, and is the same as before.

I can so something like (may not be precise ...)

select check_clause from information_schema.check_constraints where
constraint_name = 'my-name'

but this returns that clause in a normalised format that is not compatible
with the text I am trying to compare, so I'm adding something like ...

alter table my_table  add check (my_type = any (array['GOOD' , 'BAD']))

but the check_clause from above looks like ...

(((my_type)::text = ANY (ARRAY['GOOD'::text, 'BAD'::text])))

Is there a way of getting the "normalised" version of constraint so decide if
I need to update the constraint if one already exists?

Steve

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2018-03-27 11:28:07 Re: Must re-connect to see tables
Previous Message Blake McBride 2018-03-27 11:23:26 Re: Must re-connect to see tables