pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Franco Cazzaro <franco@cusa.it>
To: postrgre maillist <pgsql-sql@postgreSQL.org>
Subject: Related tables
Date: Fri, 30 Jul 1999 12:08:17 +0200
Message-ID: <002901beda73$a178df20$0201c8c0@unique.com> (raw)

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.

  
              

Message-ID: <002901beda73$a178df20$0201c8c0@unique.com>
Permalink:  ../002901beda73$a178df20$0201c8c0@unique.com/
Also on:    postgresql.org/message-id/002901beda73$a178df20$0201c8c0@unique.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: franco@cusa.it
  Subject: Re: Related tables
  In-Reply-To: <002901beda73$a178df20$0201c8c0@unique.com>
  References: <002901beda73$a178df20$0201c8c0@unique.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox