currval()

From: Marc Fromm <Marc(dot)Fromm(at)wwu(dot)edu>
To: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: currval()
Date: 2011-09-20 22:00:57
Message-ID: 93361C67E4EE844A80935863A4FF4B6C051150A2@Exch2010MB-2.univ.dir.wwu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)mail(dot)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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Steve Crawford 2011-09-20 22:52:48 Re: currval()
Previous Message Guillaume Lelarge 2011-09-20 20:09:14 Re: returning id