Re: Insert data into multiple tables - Mailing list pgsql-general

From Joel Burton
Subject Re: Insert data into multiple tables
Date
Msg-id Pine.LNX.4.21.0104241613160.19243-100000@olympus.scw.org
Whole thread Raw
In response to Re: Insert data into multiple tables  (will trillich <will@serensoft.com>)
Responses inheritance
List pgsql-general
On Tue, 24 Apr 2001, will trillich wrote:

> On Tue, Apr 17, 2001 at 05:37:31PM -0500, K Old wrote:

>     create rule cust_insert as
>         on insert to newcust
>         do instead
>         (
>             insert into customers
>                 NEW.client_id,
>                 NEW.addr_id,
>                 NEW.account_type,
>                 NEW.how_hear,
>                 NEW.cc_type,
>                 NEW.cc_exp,
>                 NEW.cc_num,
>                 NEW.sign_up_date
>             ;
>             insert into addresses
>                 NEW.addr_id
>                 NEW.fname,
>                 NEW.lname,
>                 NEW.company,
>                 NEW.addr1,
>                 NEW.addr2,
>                 NEW.city,
>                 NEW.state,
>                 NEW.zip,
>                 NEW.country,
>                 NEW.phone,
>                 NEW.fax,
>                 NEW.email
>             ;
>         );
>
> BUT -- if this is a 1:1 relation, and customers ALWAYS have
> addresses, and addresses ALWAYS have customers, then just make
> the sucker into one table and you're done.

Yep. RULEs kick ass.

If this is a 1:1 relationship, and you don't mind wandering slightly
afield of the SQL standard, inheritance is a good way to go, too.

--
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington


pgsql-general by date:

Previous
From: Joel Burton
Date:
Subject: Re: Re: BETWEEN clause
Next
From: "David Esposito"
Date:
Subject: getObject and Aggregate SQL functions