currval()

Поиск
Список
Период
Сортировка
От Marc Fromm
Тема currval()
Дата
Msg-id 93361C67E4EE844A80935863A4FF4B6C051150A2@Exch2010MB-2.univ.dir.wwu.edu
обсуждение исходный текст
Ответы Re: currval()
Re: currval()
Список pgsql-admin

I am trying to get the id of the current inserted record. The field name is ‘id’ and it is a primary key. I am obviously missing the correct syntax.

I cannot use RETURNING id.

 

$sql = "INSERT INTO jobs (job_title, num_positions, pay_min, pay_max,

                                                                startdate, enddate, job_desc, job_benefits, min_qualifications, employer_contact,

                                                                employer_phone, employer_email, stu_duties_id, stu_duties, grade_level,

                                                                employer_school, send_to, reimbursement_amt, postdate)

                                                                VALUES ('$job_title', '$num_positions', '$PAY_MIN', '$PAY_MAX',

                                                                '$startdate', '$enddate', '$job_desc', '$job_benefits', '$min_qualifications', '$employer_contact',

                                                                '$employer_phone', '$employer_email', '$stu_duties_id', '$DUTIES_DESC[$stu_duties_id]', '$grade_level',

                                                                '$employer_school', '$send_to', '$reimbursement_amt', '$postdate');";

                $sql .= "SELECT currval('id');";

               

                $result = pg_query($conn, $sql);

                $r = pg_fetch_object($result);

                $jobs_id = $r->id;

                echo "jobs id: " . $jobs_id . "<br />"; //echo is nothing

 

Any insight would be appreciated.

 

$sql echoed is this:

INSERT INTO jobs (job_title, num_positions, pay_min, pay_max, startdate, enddate, job_desc, job_benefits, min_qualifications, employer_contact, employer_phone, employer_email, stu_duties_id, stu_duties, grade_level, employer_school, send_to, reimbursement_amt, postdate) VALUES ('Paraeducator', '1', '9.50', '9.50', '9/16/2011', '6/10/2012', 'fdfd', 'fdfd', 'fdfd', 'firstn lastn', '3351', 'emailme@mail.com', '2', 'This position mostly tutors, instructs, or directly assists students. Less than half of the position tasks are clerical or support duties.', '10', '28', 'all', '70%', '09-20-2011');SELECT currval(id);

 

Marc

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

Предыдущее
От: Guillaume Lelarge
Дата:
Сообщение: Re: returning id
Следующее
От: Steve Crawford
Дата:
Сообщение: Re: currval()