pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedcheck constraints
4+ messages / 4 participants
[nested] [flat]
* check constraints
@ 2001-08-15 13:41 Danno <danny@intuitivemedia.com>
0 siblings, 0 replies; 4+ messages in thread
From: Danno @ 2001-08-15 13:41 UTC (permalink / raw)
To: pgsql-general
Is it possible to enumerate the check constraint of a
given field in a table. I want to do this dynamically
so I can populate a drop down list in a web form.
I'm using pyPgSQL to interface with Postgres from
Python.
thanks
Dann-o
^ permalink raw reply [nested|flat] 4+ messages in thread
* Check constraints.
@ 2018-03-27 11:23 Steve Rogerson <steve.pg@yewtc.demon.co.uk>
0 siblings, 1 reply; 4+ messages in thread
From: Steve Rogerson @ 2018-03-27 11:23 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Check constraints.
@ 2018-03-27 14:44 Paul Jungwirth <pj@illuminatedcomputing.com>
parent: Steve Rogerson <steve.pg@yewtc.demon.co.uk>
0 siblings, 1 reply; 4+ messages in thread
From: Paul Jungwirth @ 2018-03-27 14:44 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 03/27/2018 04:23 AM, Steve Rogerson wrote:
> I am trying to add/change a constraint programmatically, but not if it
> already exists, and is the same as before.
> ...
> Is there a way of getting the "normalised" version of constraint so decide if
> I need to update the constraint if one already exists?
Hi Steve,
I wrote a Ruby gem to do this some years ago. Here is the SQL I used:
SELECT c.conname,
t.relname,
pg_get_expr(c.conbin, c.conrelid)
FROM pg_catalog.pg_constraint c,
pg_catalog.pg_class t,
pg_catalog.pg_namespace n
WHERE c.contype = 'c'
AND c.conrelid = t.oid
AND t.relkind = 'r'
AND n.oid = t.relnamespace
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(t.oid)
https://github.com/pjungwir/db_leftovers/blob/master/lib/db_leftovers/postgres_database_interface.rb...
I haven't used it against the last few Postgres versions, but it
probably still works or needs only minor adjustments.
--
Paul ~{:-)
pj@illuminatedcomputing.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Check constraints.
@ 2018-03-27 16:14 Steve Rogerson <steve@yewtc.demon.co.uk>
parent: Paul Jungwirth <pj@illuminatedcomputing.com>
0 siblings, 0 replies; 4+ messages in thread
From: Steve Rogerson @ 2018-03-27 16:14 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 27/03/18 15:44, Paul Jungwirth wrote:
> SELECT c.conname,
> ...
This just does a variation on select * from
information_schema.check_constraints, and has the same issue, that is the the
returned value for the constraint is not what I give when I create it - but
some 'normalised' version of it.
Steve
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2018-03-27 16:14 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-08-15 13:41 check constraints Danno <danny@intuitivemedia.com>
2018-03-27 11:23 Check constraints. Steve Rogerson <steve.pg@yewtc.demon.co.uk>
2018-03-27 14:44 ` Re: Check constraints. Paul Jungwirth <pj@illuminatedcomputing.com>
2018-03-27 16:14 ` Re: Check constraints. Steve Rogerson <steve@yewtc.demon.co.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox