From: Tom Lane <tgl@sss.pgh.pa.us>
To: Giorgio Ponza <giorgio@opla.it>
Cc: pgsql-novice@postgresql.org
Subject: Re: Stupid question on INDEXES
Date: Wed, 19 Dec 2001 10:11:51 -0500
Message-ID: <29521.1008774711@sss.pgh.pa.us> (raw)
In-Reply-To: <002601c1888d$9ac2aba0$c801a8c0@opla.it>
References: <web-531103@davinci.ethosmedia.com>
<002601c1888d$9ac2aba0$c801a8c0@opla.it>
"Giorgio Ponza" <giorgio@opla.it> writes:
> I'd like to know if i think in the right way. With
> CREATE TABLE Test1 (
> my_id int,
> descr text,
> primary key (my_id))
> Postgres automatically creates an index named test1_pkey.
> If i use
> CREATE TABLE Test1 (
> my_id int,
> descr text)
> without specifying a pkey, i can write
> create unique index i_test1_pkey on (my_id).
> The only difference is that in the 2nd case i can use the name i want, or
> the usage is different?
There are two things that are different:
1. PRIMARY KEY implies NOT NULL. You'd need to declare the column as
NOT NULL in the second CREATE TABLE to have exactly equivalent
constraints.
2. When a PRIMARY KEY is declared, the column(s) become the default
columns for a FOREIGN KEY declaration in another table, so you could
write "REFERENCES Test1" without having to mention my_id as the
referenced column. Without a PRIMARY KEY, you'll have to mention my_id
explicitly. But this is only a notational convenience.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, giorgio@opla.it, pgsql-novice@postgresql.org
Subject: Re: Stupid question on INDEXES
In-Reply-To: <29521.1008774711@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox