insert with select as value

Поиск
Список
Период
Сортировка
От Milos Prudek
Тема insert with select as value
Дата
Msg-id 40D840A9.5050102@bvx.cz
обсуждение исходный текст
Ответы Re: insert with select as value  ("Marcelo Soares" <msoares@masterhoteis.com.br>)
Re: insert with select as value  (Bruno Wolff III <bruno@wolff.to>)
Re: insert with select as value  (Milos Prudek <prudek@bvx.cz>)
Re: insert with select as value  (John Sidney-Woollett <johnsw@wardbrook.com>)
Список pgsql-general
I need to insert a value = max(value)+1, where max is a select limited
by a 'where' clause. Like this:

INSERT INTO table (idthread, idsection,txt)
VALUES (
   (SELECT max(idthread)+1 FROM table WHERE  idsection = 'CZE'),  'CZE',
'sample text')
);

This works fine, except when the result of SELECT is empty - which is
true when the table is empty.

Is it possible to create a "SELECT max(idthread)+1 FROM table WHERE
idsection = 'CZE';" that will return value 1 instead of value None if
the SELECT has no results?

--
Milos Prudek
_________________
Most websites are
confused chintzy gaudy conflicting tacky unpleasant... unusable.
Learn how usable YOUR website is! http://www.spoxdesign.com

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: User Privileges using dblink
Следующее
От: "Marcelo Soares"
Дата:
Сообщение: Re: insert with select as value