Bad return type in example

From: Nikolaus Thiel <klt(at)fsfe(dot)org>
To: pgsql-docs(at)postgresql(dot)org
Subject: Bad return type in example
Date: 2017-03-08 09:00:27
Message-ID: f37673c3-8786-b493-e244-93b7dc28028e@fsfe.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

* postgresql-9.6-A4.pdf, page 891
* https://www.postgresql.org/docs/9.6/static/xfunc-sql.html#XFUNC-SQL-BASE-FUNCTIONS

Dear Doc Writers,

Would it not be better to change the return type of the following two sample functions to numeric ?

CREATE FUNCTION tf1 (accountno integer, debit numeric) RETURNS integer AS $$
UPDATE bank
SET balance = balance - debit
WHERE accountno = tf1.accountno;
SELECT balance FROM bank WHERE accountno = tf1.accountno;
$$ LANGUAGE SQL;

CREATE FUNCTION tf1 (accountno integer, debit numeric) RETURNS integer AS $$
UPDATE bank
SET balance = balance - debit
WHERE accountno = tf1.accountno
RETURNING balance;
$$ LANGUAGE SQL;

Since debit is of type numeric, balance is (probably) numeric too, so the function ought to return numeric. I guess that the function works as it is using implicit type cast.

With best regards,
Nikolaus Thiel

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Jürgen Purtz 2017-03-08 09:29:20 Terminology
Previous Message Magnus Hagander 2017-03-08 03:47:56 Re: Grammar error