Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a48fg-0003u2-QO for pgsql-sql@arkaria.postgresql.org; Wed, 02 Dec 2015 14:46:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a48fg-0004AG-Cs for pgsql-sql@arkaria.postgresql.org; Wed, 02 Dec 2015 14:46:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a48ff-0004A7-TZ for pgsql-sql@postgresql.org; Wed, 02 Dec 2015 14:46:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a48fc-0005CD-Qm for pgsql-sql@postgresql.org; Wed, 02 Dec 2015 14:46:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id tB2Ek9mo014839; Wed, 2 Dec 2015 09:46:10 -0500 From: Tom Lane To: Andreas Kretschmer cc: pgsql-sql@postgresql.org Subject: Re: unique constraint definition within create table In-reply-to: <20151202063621.GA5526@tux> References: <20151202063621.GA5526@tux> Comments: In-reply-to Andreas Kretschmer message dated "Wed, 02 Dec 2015 07:36:21 +0100" Date: Wed, 02 Dec 2015 09:46:09 -0500 Message-ID: <14838.1449067569@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Andreas Kretschmer writes: > i'm trying to create a table with 2 int-columns and a constraint that a > pair of (x,y) cannot be as (y,x) inserted: > test=# create table foo(u1 int,u2 int, unique (least(u1,u2),greatest(u1,u2))); > ERROR: syntax error at or near "(" > LINE 1: create table foo(u1 int,u2 int, unique (least(u1,u2),greates... > I know, i can solve that in this way: > test=*# create table foo(u1 int,u2 int); > CREATE TABLE > test=*# create unique index idx_foo on foo(least(u1,u2),greatest(u1,u2)); > CREATE INDEX > But is there a way to define the unique constraint within the create table - command? No. Per SQL standard, the argument of a UNIQUE (or PRIMARY KEY) constraint can only be a list of column names. We would consider relaxing that, except it would break the information_schema views for such constraints. regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql