Use for OID, or retrieving a just-inserted row - Mailing list pgsql-general

From
Subject Use for OID, or retrieving a just-inserted row
Date
Msg-id OJKKKNPBAFGIBAAA@my-deja.com
Whole thread Raw
List pgsql-general
The docs say that a successful one-row INSERT returns: INSERT <oid> 1,
where <oid> is some kind of identifier for the row that was inserted.

I want to have a table for content:

    create table content (
        id serial primary key,
        stuff text
    );

And a separate table for the use of that content:

    create table uses (
        id serial primary key,
        name varchar (100),
        content_id integer references content (id)
    );

When a user adds some new, titled content, I would like to:

    1) INSERT INTO content (stuff) VALUES ($stuff)
    2) Somehow discover the serial id generated for that insert
    3) INSERT INTO uses (name, content_id) VALUES ($title, $content_id)

And I would like this to happen even if another user is adding content
concurrently.  So the problem is discovering (2), which was generated
automatically when (1) occured.  Is there some way to use the return
message from (1) to access to row?

I also thought of breaking down (1) into:

    a) Find the nextval of the content_seq_id table.
    b) Do the INSERT specifying that nextval.

This would give me the content id, but I'm worried that I wouldn't be
secure against a concurrent transaction that was trying the same thing.

If someone could help me out here, I think it would clear up a lot of
questions that I have about PostgreSQL.  (I would also like to ask where
the documentation is for BLOBs, but I don't want to push your patience.)

Thank you!



--== Sent via Deja.com http://www.deja.com/ ==--
Share what you know. Learn what you don't.

pgsql-general by date:

Previous
From: "rony khoury"
Date:
Subject: subscirbe
Next
From: Zakkr
Date:
Subject: Re: [GENERAL] Slow lookups on dates? Or something else?