Re: [SQL] quastions about primary key

2003-01-25 Thread jack

I try use uique instead of primary key. And it works, it allows null values.
Is there any other difference between primary key and unique?

Jack
- Original Message -
From: "Stephan Szabo" <[EMAIL PROTECTED]>
To: "jack" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, January 25, 2003 1:14 AM
Subject: Re: [SQL] quastions about primary key


> On Fri, 24 Jan 2003, jack wrote:
>
> > Is that possible to have a two columns primary key on a table with null
> > value on second column?
>
> No, because primary key implies not null on all columns involved
> (technically I think it's that a non-deferrable primary key implies
> not null on all columns involved, but we don't support deferrable ones)
>
>


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [SQL] returning setof in plpgsql

2003-01-25 Thread Bruce Momjian

I thought we had an example of this type of function in the docs, but we
don't.  Here is one:


http://www.brasileiro.net:8080/postgres/cookbook/view-recipes.adp?section_id=535&format=long

---

Tom Lane wrote:
> "David Durst" <[EMAIL PROTECTED]> writes:
> > CREATE FUNCTION lookup_account(varchar(32)) RETURNS SETOF accounts AS '
> > DECLARE
> >   aname ALIAS FOR $1;
> >   rec RECORD;
> > BEGIN
> >   select into rec * from accounts where accountname = aname;
> >   return rec;
> > END;'
> > LANGUAGE 'plpgsql';
> 
> As written, this function can only return a single row (so you hardly
> need SETOF).  If you intend that it be able to return multiple rows
> when accountname is not unique, then you'll need a loop and RETURN NEXT
> commands.  It'd probably be less tedious to use a SQL-language function:
> 
> CREATE FUNCTION lookup_account(varchar(32)) RETURNS SETOF accounts AS '
> select * from accounts where accountname = $1'
> language sql;
> 
> > This seems to hang when I attempt to select it using:
> 
> > select accountid(
> > lookup_account('some account')),
> > accountname(lookup_account('some account')),
> > type(lookup_account('some account')),
> > balance(lookup_account('some account'));
> 
> It works for me (in 7.3), but in any case that's a bad approach: you're
> invoking the function four times, independently.  Better is
> 
> select accountid,accountname,type,balance
> from lookup_account('some account');
> 
> (again, this syntax requires 7.3)
> 
>   regards, tom lane
> 
> ---(end of broadcast)---
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to [EMAIL PROTECTED] so that your
> message can get through to the mailing list cleanly
> 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster



Re: [SQL] quastions about primary key

2003-01-25 Thread Bruno Wolff III
On Sun, Jan 26, 2003 at 12:29:12 +1000,
  jack <[EMAIL PROTECTED]> wrote:
> 
> I try use uique instead of primary key. And it works, it allows null values.
> Is there any other difference between primary key and unique?

I believe that the primary key is the default key for foreign key references
into a table.

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html