Received: from nw.netwheel.com (root@nw.netwheel.com [193.76.229.27]) by hub.org (8.9.3/8.9.3) with ESMTP id GAA37789 for ; Fri, 30 Jul 1999 06:07:24 -0400 (EDT) (envelope-from franco@cusa.it) Received: from axy.unique.com ([193.76.229.131]) by nw.netwheel.com (8.8.3/8.8.3) with SMTP id LAA03215 for ; Fri, 30 Jul 1999 11:14:01 +0200 Message-ID: <002901beda73$a178df20$0201c8c0@unique.com> From: "Franco Cazzaro" To: "postrgre maillist" Subject: Related tables Date: Fri, 30 Jul 1999 12:08:17 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0026_01BEDA84.3524E060" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.0810.800 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800 This is a multi-part message in MIME format. ------=_NextPart_000_0026_01BEDA84.3524E060 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, First sorry for my elementary english. I'm new in Postgre and, naturally need help. Can anyones courtesely help in this simplified relaction? table T1(=20 ID serial primary key, NAME text unique, morefields...... ); table T2( oID int4, --join to T1.ID NOTE text ); Now, extraction is very easy: select NAME,NOTE from T1, T2 where T1,ID=3D T2.oID; but, how can I insert a NOTE of a NAME automatically inserting NAME in = T1 if does not exists ? I'm thinking about a function that: function TI_ID( text ) RESULTS int4 IF new.NAME does not exists in T1, THEN insert new.NAME and = return the related new.ID ELSE returns the related ID of existing NAME. language ......; Please, I'm looking for simple sintax. Thanks for time. Ciao. =20 =20 ------=_NextPart_000_0026_01BEDA84.3524E060 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
First sorry for my elementary = english.
 
I'm new in Postgre and, naturally need=20 help.
 
Can anyones courtesely help in this = simplified=20 relaction?
 
 
table T1(
    ID serial primary=20 key,
    NAME text = unique,
    = morefields......
);
 
 
table T2(
    oID=20 int4,         --join to=20 T1.ID
    NOTE = text
    );
 
Now, extraction is very = easy:
select NAME,NOTE from T1, T2 where = T1,ID=3D=20 T2.oID;
 
but, how can I insert a NOTE of a NAME=20 automatically inserting NAME in T1 if does not exists ?
 
I'm thinking about a function = that:
 
    function TI_ID( text = )
    RESULTS = int4
      =20     IF  new.NAME does not exists in T1, THEN = insert=20 new.NAME and return the related new.ID
           = ELSE returns=20 the related ID of existing NAME.
   language = ......;
 
Please, I'm looking for simple = sintax.
 
 
Thanks for time.
Ciao.
 
 
          &nbs= p;  =20
 
 
 
 
------=_NextPart_000_0026_01BEDA84.3524E060--