Re: plpgsql question

Поиск
Список
Период
Сортировка
От Matthew Peter
Тема Re: plpgsql question
Дата
Msg-id 20060109210133.33296.qmail@web35201.mail.mud.yahoo.com
обсуждение исходный текст
Ответ на Re: plpgsql question  (Michael Fuhr <mike@fuhr.org>)
Ответы Re: plpgsql question  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-general
snip
WHERE my_tbl_id = $1
AND CASE WHEN $2 IS NULL THEN TRUE ELSE $2 = username END

or

WHERE my_tbl_id = $1 AND COALESCE($2 = username, TRUE)

or

WHERE my_tbl_id = $1 AND COALESCE($2, username) = username

With predicates such as these you wouldn't need to use EXECUTE and
you could write the query only once.
That did work. Thanks.

One other quick question, (figure it still applies to the subject line :) when returning a row from a function I'm trying to include an aggregate, but it's not showing up in the query result and I think it's because it's not included in the RETURN NEXT row;?  How do I return it as part of the resultset...

create or replace function getrecord(int,text) RETURNS SETOF my_tblas $$
DECLARE
row my_tbl%rowtype;

BEGIN
FOR row IN SELECT *, SUBSTR(title,1,25) as short_title FROM my_tbl
WHERE ...
LOOP
RETURN NEXT row;
END LOOP;

RETURN;

END;
$$ LANGUAGE plpgsql;
Thanks


Yahoo! Photos
Got holiday prints? See all the ways to get quality prints in your hands ASAP.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: function overloading
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pg_dump creates bad dump / pgadmin crash issue