Use for OID, or retrieving a just-inserted row

Поиск
Список
Период
Сортировка
От
Тема Use for OID, or retrieving a just-inserted row
Дата
Msg-id OJKKKNPBAFGIBAAA@my-deja.com
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: "rony khoury"
Дата:
Сообщение: subscirbe
Следующее
От: Zakkr
Дата:
Сообщение: Re: [GENERAL] Slow lookups on dates? Or something else?