No subject


Tue Nov 29 10:43:08 WST 2011


    CREATE [ UNIQUE ] INDEX index_name ON table
        [ USING acc_method ] ( column [ ops_name ] [, ...] )
        [ WHERE predicate ]

Y'know, it sure looks like UNIQUEness is optional. (-:

The documentation's comment on the UNIQUE keyword is:

    UNIQUE

    Causes the system to check for duplicate values in the table when
    the index is created (if data already exist) and each time data is
    added. Attempts to insert or update data which would result in
    duplicate entries will generate an error.

I can think of lots of uses for a non-unique index. Software to plan courier 
routes would probably like to start by looking up addresses in postcode 
order, for example.

You can also allow for prohibit UNIQUEness even in the absence of indeces 
(PostgreSQL will silently create nameless indeces if necessary in order to 
fulfil contraint checking requirements), for individual columns or groups of 
columns. PRIMARY KEY for PostgreSQL is almost a synonym for UNIQUE NOT NULL. 
And then there is the CHECK constraint if you really want to be sure, and the 
handy REFERENCES contraint if you have a set of possible values tucked away 
in another table somewhere.

I wouldn't have to head-scratch for long to find uses for multiple 
auto-incrementing fields either, BoC in PostgreSQL you can attach a function 
to the field and auto-square or auto-add-Pi to it or whatever lights up your 
beacon when a new record arrives. Or when the record is updated, deleted, 
name it, per column or per table. And I'm sure that if you wanted to grow old 
reading Oracle manuals, you'd find even more tricks in there.

Cheers; Leon



More information about the plug mailing list