Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VSBNP-0006x7-KJ for pgsql-sql@arkaria.postgresql.org; Fri, 04 Oct 2013 19:49:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VSBNP-0007JD-1A for pgsql-sql@arkaria.postgresql.org; Fri, 04 Oct 2013 19:49:27 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VSBNN-0007J6-S1 for pgsql-sql@postgresql.org; Fri, 04 Oct 2013 19:49:26 +0000 Received: from mail-pd0-x236.google.com ([2607:f8b0:400e:c02::236]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VSBNK-0000gD-4c for pgsql-sql@postgresql.org; Fri, 04 Oct 2013 19:49:24 +0000 Received: by mail-pd0-f182.google.com with SMTP id r10so4488640pdi.27 for ; Fri, 04 Oct 2013 12:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=8aamVXhP0m085cZiY66tUTtIETjMPFDvlne88mpzm8g=; b=bBCnc274jrh35xQ7q3BoRIcfJJ0ykSDauc5bmGdq6nPzrQq3zAgyFymJvyxhgZ7B6F PMdyaxJdH7rvKaY5IkIvPOeEDdQoSTUPt0/PZXM/ODCQJD7oSEDBv/9h+tJiyNVJRtPO IjW9zeDkm2Eqgd4c6HD/TNXH9Q15gBSaaloM7hbu5qczfogHqI+Vk7y4G9SIvU3viYgX UTlu9pE4bC3pQsYSCpuRhHyaooLb6y6GUfnJnS0QGKnFE2033NYm/KODpfae2tXbEwxt FyLeSVVaG0kuax/1ru3Utaq7kr+VWnpPFGGprMsRiKoKs+mxHUYRTW4MjEdt5ia6yN2k jhbw== X-Received: by 10.68.197.3 with SMTP id iq3mr8120828pbc.113.1380916161128; Fri, 04 Oct 2013 12:49:21 -0700 (PDT) Received: from killi.site ([199.48.193.199]) by mx.google.com with ESMTPSA id yo2sm20123640pab.8.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Oct 2013 12:49:20 -0700 (PDT) Message-ID: <524F1BBE.2070708@gmail.com> Date: Fri, 04 Oct 2013 12:49:18 -0700 From: Adrian Klaver User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: "lucazeo@gmail.com" CC: pgsql-sql@postgresql.org Subject: Re: Unique index VS unique constraint References: <524EFDBD.9010204@gmail.com> In-Reply-To: <524EFDBD.9010204@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.6 (/) 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 On 10/04/2013 10:41 AM, lucazeo@gmail.com wrote: > Il 04/10/2013 18:48, JORGE MALDONADO ha scritto: >> I have search for information about the difference between "unique >> index" and "unique constraint" in PostgreSQL without getting to a >> specific answer, so I kindly ask for an explanation that helps me >> clarify such concept. > > 2 main differences. > > First is the meaning: primary key identifies a record. A unique just > tells you that that value of the record, in the table is unique. If you > use keys, db structure will be more intelligible (my opinion). Not sure I follow, you can have a unique index that is not a primary key. A primary key is special kind of unique index: http://www.postgresql.org/docs/9.3/interactive/sql-createtable.html The primary key constraint specifies that a column or columns of a table can contain only unique (non-duplicate), nonnull values. Technically, PRIMARY KEY is merely a combination of UNIQUE and NOT NULL, but identifying a set of columns as primary key also provides metadata about the design of the schema, as a primary key implies that other tables can rely on this set of columns as a unique identifier for rows. > > Second one is functional: in an unique constraint you can allow NULL > values and ignore them. A primary key does not allow this. > >> Respectfully, >> Jorge Maldonado > > Regards, > > Luca. > > -- Adrian Klaver adrian.klaver@gmail.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql