Perhaps pg_last_oid() will help:

http://www.php.net/manual/en/function.pg-last-oid.php

--Dave

Dave wrote:
Hi everyone, I am new to the forum.

I am using PHP and PostgreSQL.

After I insert into a table "Task" who's primary key is a serial type (auto
sequence number) I would like to immediately retrieve that generated
sequence number to use for subsequent inserts into another table "Points."

So what is a correct and safe way to guarantee I can retrieve this record,
without requiring another indexed (and unique) field?

Example:
    //run in php, insert a new TASK
    INSERT INTO Task
        ("taskname", "taskstat")
    VALUES
        ("my new task", 0);

    //this part I need help with.
        //get the task_id of the new task from above
        $new_task_id = ????????;

    //run in php, insert a POINT, referencing the new TASK
    INSERT INTO Point
        ("task_id", "ptnotes")
    VALUES
        ($new_task_id, "this is a point with foreign key reference to the
new task");






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to