Insert data into multiple tables

From: "K Old" <kevsurf4(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Insert data into multiple tables
Date: 2001-04-17 22:37:31
Message-ID: F205Xix4A2DreBBsQwY00000013@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I have a general question about inserting data.

I have the following tables:

CREATE TABLE customer (
client_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
addr_id INT,
account_type INT,
how_hear INT,
cc_type INT,
cc_exp VARCHAR(5),
cc_num VARCHAR(16),
sign_up_date DATE
);

CREATE TABLE addresses (
addr_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
fname VARCHAR(16),
lname VARCHAR(16),
company VARCHAR(72),
addr1 VARCHAR(72),
addr2 VARCHAR(48),
city VARCHAR(32),
state VARCHAR(3),
zip VARCHAR(16),
country VARCHAR(32),
phone VARCHAR(18),
fax VARCHAR(18),
email VARCHAR(74)
);

I need to insert data into both of these tables at one time. I want to have
the "addr_id" field in the addresses tables to be included in the insert of
data to the customer table.

My solution so far is to have 1 insert statement that inserts the
appropriate data into the addresses table (creating a record), then have a
select statement pull back the most recent (which is only milliseconds old)
record from addresses and get the addr_id (it would probably be set to a
variable) then when all other data is gathered for the customer insert the
addr_id would be included in that insert.

This seems really difficult to do a simple insert and I was wondering if
anyone knew if I could use something like a view that would allow me to
insert into multiple tables with one statement? I didn't see anything
reguarding views in the documentation.

Any ideas how to solve this?

Thanks,
Kevin
kevsurf4(at)hotmail(dot)com
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-04-17 22:50:39 Re: scan.c:900: warning: ... postgresql-7.1
Previous Message Justin Clift 2001-04-17 22:22:12 Re: Re: Re: erServer beta