Re: data integrity and inserts - Mailing list pgsql-general

From Scott Frankel
Subject Re: data integrity and inserts
Date
Msg-id 9E3F9598-43C9-11D9-9E72-000A95A7B782@pacbell.net
Whole thread Raw
In response to data integrity and inserts  (Scott Frankel <leknarf@pacbell.net>)
Responses Re: data integrity and inserts  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-general
1.
CREATE TABLE names (the_id SERIAL PRIMARY KEY, the_name text);
CREATE UNIQUE INDEX uidx_thename ON names(the_name);

    vs.

2.
CREATE TABLE names (the_id SERIAL PRIMARY KEY, the_name text UNIQUE);


Is the UNIQUE constraint in the second solution merely short-hand for
the explicit
index declaration of the first solution?  Or is there a functional
difference between
them that I should choose between?

Thanks again!
Scott




On Dec 1, 2004, at 10:11 AM, Scott Frankel wrote:

>
> I want to ensure data integrity when inserting into a table,
> preventing multiple
> entries of identical rows of data.
>
> Does this call for using a trigger?
> How would triggers perform a query to test if data already exists in
> the table?
>
> (The doco outlines how triggers perform tests on NEW data inserted
> into a
> table; but I haven't found anything on data already extant.)
>
> Thanks in advance!
> Scott
>
>
> sample table:
>
> CREATE TABLE names (the_id SERIAL PRIMARY KEY, the_name text);
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


pgsql-general by date:

Previous
From: Michelle Konzack
Date:
Subject: Re: USENET vs Mailing Lists Poll ...
Next
From: "gnari"
Date:
Subject: Re: autocommit and transactions