if exists, select; if not, create then select... ??

Поиск
Список
Период
Сортировка
От will trillich
Тема if exists, select; if not, create then select... ??
Дата
Msg-id 20010515014632.A18580@serensoft.com
обсуждение исходный текст
Список pgsql-general
okay. i seem to recall some discussion on pl/pgsql wherein a
function called via SELECT can't do an INSERT.

is there a way to do something like

    select get_or_create(...);

which runs some pl/pgsql such as

    select * from tbl where...;
    if not found
        insert into tbl values (...);
        select * from tbl where...;
    end if;
    return found stuff, even if we had to create it...

or not?

i'm looking for results similar to perl code like

    $something ||= &make_new();
    # which translates to (more or less, for this application)
    if ( ! defined( $something ) ) {
        $something = &make_new();
    }
    return $something;

i've tried conceiving of a rule that might intervene properly,
but i'm stymied...

--
What do I need manners for? I already got me a wife.
-- Adam Pontipee, "Seven Brides for Seven Brothers"

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

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

Предыдущее
От: Justin Clift
Дата:
Сообщение: Re: PostgreSQL in Comparison to mySQL
Следующее
От: Lincoln Yeoh
Дата:
Сообщение: index ops for _int4 and trees?