Related tables - Mailing list pgsql-sql

From Franco Cazzaro
Subject Related tables
Date
Msg-id 002901beda73$a178df20$0201c8c0@unique.com
Whole thread Raw
List pgsql-sql
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(
    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= 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.
 
 
             
 
 
 
 

pgsql-sql by date:

Previous
From: Yann-Ju Chu
Date:
Subject: stuck spinlock in postgresql-6.5.1
Next
From: "Esteban Chiner Sanz"
Date:
Subject: Error when inserting