Related tables

From: "Franco Cazzaro" <franco(at)cusa(dot)it>
To: "postrgre maillist" <pgsql-sql(at)postgreSQL(dot)org>
Subject: Related tables
Date: 1999-07-30 10:08:17
Message-ID: 002901beda73$a178df20$0201c8c0@unique.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.


Browse pgsql-sql by date

  From Date Subject
Next Message Esteban Chiner Sanz 1999-07-30 11:36:27 Error when inserting
Previous Message Yann-Ju Chu 1999-07-30 02:17:44 stuck spinlock in postgresql-6.5.1