pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bad return type in example
2+ messages / 2 participants
[nested] [flat]

* Bad return type in example
@ 2017-03-08 09:00  Nikolaus Thiel <klt@fsfe.org>
  0 siblings, 1 reply; 2+ messages in thread

From: Nikolaus Thiel @ 2017-03-08 09:00 UTC (permalink / raw)
  To: 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

Attachments:

  signature.asc (application/pgp-signature, 841B) download

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Bad return type in example
@ 2017-06-09 23:51  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Nikolaus Thiel <klt@fsfe.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2017-06-09 23:51 UTC (permalink / raw)
  To: klt@fsfe.org; pgsql-docs

On 3/8/17 04:00, Nikolaus Thiel wrote:
>   * 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 ?

fixed

> 
> 
> 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;

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2017-06-09 23:51 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-03-08 09:00 Bad return type in example Nikolaus Thiel <klt@fsfe.org>
2017-06-09 23:51 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox