From: | Kumar S <ps_postgres(at)yahoo(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | How to capture MAX id value into a variable |
Date: | 2004-11-17 23:51:47 |
Message-ID: | 20041117235147.39628.qmail@web51401.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Dear group,
I have two tables (say Employee and Duty). Duty
table is linked to employee table by employee_id key.
Other than this there is not other data fields
overlapping the tables.
I have my data in an Excel sheet. The first 3 columns
of this data sheet should go into Employee table and
the next 3 columns to DUTY table.
I am writing a python script that write SQL
statements:
INSERT INTO EMPLOYEE(<columns>) VALUES(
col1,col2,col3);
SELECT INTO X = SELECT MAX(employee_id) from employee;
INSERT INTO DUTY(<cols>) VALUES(X, col4,col4,col6);
Here I want to capture the MAX employee_id into a
variable X and then I want to write it into the next
table. By this I am filling the foreign key
(employee_id) in DUTY table.
My question:
1. How to capture select max value into a variable X
as an SQL statement?
2. Is this a better approach or is there any other
alternative that I can choose.
Please help me.
thanks
Kumar.
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2004-11-18 00:35:54 | Re: How to capture MAX id value into a variable |
Previous Message | Michael Guerin | 2004-11-17 22:43:47 | ERROR: cache lookup failed for relation |