X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 7DBEA9FB321 for ; Thu, 10 Aug 2006 16:25:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 67854-06 for ; Thu, 10 Aug 2006 19:25:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from my.endian.it (unknown [62.146.87.34]) by postgresql.org (Postfix) with ESMTP id 945869FB31F for ; Thu, 10 Aug 2006 16:25:34 -0300 (ADT) Received: from dell.home.lan (host188-110.pool874.interbusiness.it [87.4.110.188]) (authenticated (0 bits)) by my.endian.it (8.11.6/8.11.6) with ESMTP id k7AJXDT31922; Thu, 10 Aug 2006 21:33:13 +0200 Subject: Re: Querying constraints? From: Chris Mair To: Lexington Luthor Cc: pgsql-sql@postgresql.org In-Reply-To: References: Content-Type: text/plain Date: Thu, 10 Aug 2006 21:25:20 +0200 Message-Id: <1155237920.5893.50.camel@dell.home.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27) Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200608/69 X-Sequence-Number: 26027 > Is is possible to query from my application whether there is a primary > key or unique constraint on a given table and field name(s)? Curiously enough, I just answered a similar question on the pgsql-admin list. Try this: SELECT c.relname as table, r.conname as contraint_name, r.contype as contraint_type, pg_catalog.pg_get_constraintdef(r.oid, true) as constraint_definition FROM pg_catalog.pg_constraint r, pg_catalog.pg_class c WHERE c.oid = r.conrelid; Bye, Chris -- Chris Mair http://www.1006.org