Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2013
    Posts
    13

    Unanswered: How to get check clause from system tables?

    I am trying to get the check clause from the system tables.
    I looked at information_schema - check_constraints and table_constraints.
    pg_catalog.pg_constraint.

    I can't figure out how to link the tables to give me the check clause.
    I think pg_catalog.pg_constraint is the key.

    Update:
    SELECT c.oid,conname,conrelid,consrc FROM pg_catalog.pg_class c, pg_catalog.pg_constraint WHERE c.oid = conrelid AND contype = 'c' AND c.relname = 'MyTable'

    I think I solved it. Hope this is the correct method.
    Last edited by GaryK4; 04-14-14 at 19:55.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Not all constraints will be listed with that. If you e.g. have an exclusion constraint it won't show up in consrc.

    In that case you'd have have to use pg_get_constraintdef() in order to get the full definition.

    And please use [code] tags in the future to format your SQL code.
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •