How to capture MAX id value into a variable

Поиск
Список
Период
Сортировка
От Kumar S
Тема How to capture MAX id value into a variable
Дата
Msg-id 20041117235147.39628.qmail@web51401.mail.yahoo.com
обсуждение исходный текст
Ответы Re: How to capture MAX id value into a variable  (Michael Fuhr <mike@fuhr.org>)
Список 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



В списке pgsql-novice по дате отправления:

Предыдущее
От: Michael Guerin
Дата:
Сообщение: ERROR: cache lookup failed for relation
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: How to capture MAX id value into a variable