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

    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.

    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.

    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
    Provided Answers: 23
    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:

    Tips for good questions:

Posting Permissions

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