Related tables

Поиск
Список
Период
Сортировка
От Franco Cazzaro
Тема Related tables
Дата
Msg-id 002901beda73$a178df20$0201c8c0@unique.com
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Yann-Ju Chu
Дата:
Сообщение: stuck spinlock in postgresql-6.5.1
Следующее
От: "Esteban Chiner Sanz"
Дата:
Сообщение: Error when inserting