Insert into two tables

From: "Robby Slaughter" <webmaster(at)robbyslaughter(dot)com>
To: "Postgres Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Insert into two tables
Date: 2001-06-18 21:18:57
Message-ID: EPEHLKLEHAHLONFOKNHNOEHCDBAA.webmaster@robbyslaughter.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

This seems like such a common place procedure that I figure there had
to be a "right" way to do it.

I've got two tables, orders and order_items. orders has a primary
key "ordersid" and order_items has a foreign key, orderid (which
obviously references orders.ordersid)

Say I want to create a new order and put some items into it. If
I use an autoincrement field I could just:

INSERT INTO orders VALUES ( ... );

And then I need to get the orderid I just created to create
new records in the orderitems table So am I supposed to
immediately do a:

SELECT ordersid FROM orders ORDER BY ordersid DESC LIMIT 1;

And then get the value, and then do inserts in the order items
table? Surely there's some way to wrap this all up into a
nice little procedure or something.

Thanks----

-Robby

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org]On Behalf Of Frank Hilliard
Sent: Monday, June 18, 2001 2:05 PM
To: Postgres Novice
Subject: [NOVICE] Display version

I've just figured out how to display the PostgreSQL version number in
Cold Fusion. Here's the code:
<CFQUERY NAME="getversion" DATASOURCE="yourdatasource"> SELECT
version();</CFQUERY>
<CFOUTPUT>#getversion.version</CFOUTPUT>
Best regards,
Frank Hilliard
http://frankhilliard.com/

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Robby Slaughter 2001-06-18 22:54:31 RE: Insert into two tables
Previous Message Tom Lane 2001-06-18 20:06:28 Re: Parse error creating tables