PL/PGSQL question

Поиск
Список
Период
Сортировка
От Jean-Christian Imbeault
Тема PL/PGSQL question
Дата
Msg-id 3E279E1C.9060309@mega-bucks.co.jp
обсуждение исходный текст
Ответы Re: PL/PGSQL question  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: PL/PGSQL question  (elein <elein@sbcglobal.net>)
Список pgsql-general
I wrote the following plpgsql function. The problem I have is that if no
rows are found my function returns NULL whereas it should be returning 0.

Where have I erred?

create or replace function zoqoo_total_sales(integer) returns integer as '
   declare total_sales integer := 0;
   begin
     select into total_sales sum(price)
     from invoice_li, invoices WHERE
       shop_id=$1 AND not invoice_li.cancelled
       AND shipped AND invoices.id=invoice_id
       AND not invoices.cancelled AND payment_rcvd;
     IF NOT FOUND THEN
       RETURN 0;
     END IF;
     RETURN total_sales;
   end;
' language 'plpgsql' with (iscachable);


JC=# select zoqoo_total_sales(1);
  zoqoo_total_sales
-------------------

(1 row)

Thanks,

Jc


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

Предыдущее
От: trainee12@yeah.net
Дата:
Сообщение: Re: varchar and spaces problem..
Следующее
От: Tom Lane
Дата:
Сообщение: Re: PL/PGSQL question