Re: [SQL] Creating table with unique key.

From: Tom Good <tomg(at)nrnet(dot)org>
To: Richard Lynch <lynch(at)lscorp(dot)com>
Cc: Colin Dick <cdick(at)mail(dot)ocis(dot)net>, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Creating table with unique key.
Date: 1998-08-06 12:16:44
Message-ID: Pine.LNX.3.95.980806080723.2040A-100000@mailhost.nrnet.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 5 Aug 1998, Richard Lynch wrote:

> www.postgresql.org/docs/man/create_table.1.html does not seem to allow for
> any spiffy keywords like UNIQUE nor PRIMARY KEY... at least not if I'm
> understanding it properly.
>
> Disclaimer: I think the docs are wrong, not that at least one of them
> won't work.

Rich & Colin,

Have a look below at how I convince pg to make a p_key with a check
constraint...I got this from the man page and (even better methinks)
from \h <cmd> at the isql prompt.

/***********************************************************************
#!/usr/bin/perl -w
use DBI;
use strict;

my $dbh = DBI->connect("dbi:Pg:dbname=registry", "", "", { RaiseError => 1 });

my $rv =
$dbh->do( "
CREATE TABLE central
(client_lname char (15) not null, client_fname char (15) not null,
client_id int not null primary key check (client_id > 100000),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

a_lias char (25), home_stat char (30), home_less int,
address_1 char (40), zip_code char (10), client_dob date,
gen_der char (1), eth_nic char (8), marital_stat char (10),
diagnosis_1 char (40), diagnosis_2 char (40), dsm_1 char (6),
dsm_2 char (6), drug_use char (1), alcohol char (1),
gambler char (1), in_out char (1), t_date date,
place_ment char (25), sent_to char (25), input_by char (40));
" );

$dbh->disconnect;
exit;
***********************************************************************/

Cheers,
Tom

----------- Sisters of Charity Medical Center ----------
Department of Psychiatry
----
Thomas Good, System Administrator <tomg(at)q8(dot)nrnet(dot)org>
North Richmond CMHC/Residential Services Phone: 718-354-5528
75 Vanderbilt Ave, Quarters 8 Fax: 718-354-5056
Staten Island, NY 10304 www.panix.com/~ugd
----
Powered by PostgreSQL 6.3.2 / Perl 5.004 / DBI-0.91::DBD-PG-0.69

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Good 1998-08-06 12:20:04 Re: [SQL] What is the recommended machine configuration?
Previous Message Stuart logan 1998-08-06 08:37:01 Installing PostgreSQL 6.3.2 on Linux