Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clfrt-0007Qn-IL for pgsql-docs@arkaria.postgresql.org; Wed, 08 Mar 2017 17:59:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1clfrt-0005Hd-4w for pgsql-docs@arkaria.postgresql.org; Wed, 08 Mar 2017 17:59:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1clXSY-0002ns-1G for pgsql-docs@postgresql.org; Wed, 08 Mar 2017 09:00:38 +0000 Received: from smtp3.zaclys.net ([178.33.93.72] helo=mail.zaclys.net) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1clXSR-0005tr-4V for pgsql-docs@postgresql.org; Wed, 08 Mar 2017 09:00:37 +0000 Received: from EiMaegg.local (77-57-169-218.dclient.hispeed.ch [77.57.169.218]) (authenticated bits=0) by mail.zaclys.net (8.14.7/8.14.7) with ESMTP id v2890SXV009599 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Wed, 8 Mar 2017 10:00:28 +0100 From: Nikolaus Thiel Subject: Bad return type in example Reply-To: klt@fsfe.org To: pgsql-docs@postgresql.org Organization: Free Software Foundation Europe Message-ID: Date: Wed, 8 Mar 2017 10:00:27 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="8A1KLgNfQFCaHvELhO3Nisp2nN16jL0vd" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --8A1KLgNfQFCaHvELhO3Nisp2nN16jL0vd Content-Type: multipart/mixed; boundary="5pHrnKdwuFuslOWMVdaQDt3uepqbsfv46"; protected-headers="v1" From: Nikolaus Thiel Reply-To: klt@fsfe.org To: pgsql-docs@postgresql.org Message-ID: Subject: Bad return type in example --5pHrnKdwuFuslOWMVdaQDt3uepqbsfv46 Content-Type: multipart/alternative; boundary="------------CD25C3DB23708C46ED01D822" This is a multi-part message in MIME format. --------------CD25C3DB23708C46ED01D822 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable * postgresql-9.6-A4.pdf, page 891 * https://www.postgresql.org/docs/9.6/static/xfunc-sql.html#XFUNC-SQL-B= ASE-FUNCTIONS Dear Doc Writers, Would it not be better to change the return type of the following two sam= ple functions to numeric ? CREATE FUNCTION tf1 (accountno integer, debit numeric) RETURNS integer AS= $$ UPDATE bank SET balance =3D balance - debit WHERE accountno =3D tf1.accountno; SELECT balance FROM bank WHERE accountno =3D tf1.accountno; $$ LANGUAGE SQL; CREATE FUNCTION tf1 (accountno integer, debit numeric) RETURNS integer AS= $$ UPDATE bank SET balance =3D balance - debit WHERE accountno =3D 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 --------------CD25C3DB23708C46ED01D822 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

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 $$
=
=C2=A0=C2=A0=C2=A0 UPDATE bank
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SET balance =3D= balance - debit
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 WHERE accountno= =3D tf1.accountno;
=C2=A0=C2=A0=C2=A0 SELECT balance FROM bank WHERE accountn= o =3D tf1.accountno;
$$ LANGUAGE SQL;


CREATE FUNCTION tf1 (accountno integer, debit numeric) RETURNS integer AS $$
=
=C2=A0=C2=A0=C2=A0 UPDATE bank
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SET balance =3D= balance - debit
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 WHERE accountno= =3D tf1.accountno
=C2=A0=C2=A0=C2=A0 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


--------------CD25C3DB23708C46ED01D822-- --5pHrnKdwuFuslOWMVdaQDt3uepqbsfv46-- --8A1KLgNfQFCaHvELhO3Nisp2nN16jL0vd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJYv8gsAAoJEBQt97HwgbqJe7EQAJ6DPtZomSbARylsie5xQQst +4S90UV/nCehr6I+aL77PK2ta/4m+RB9zxdCgodaoGmJV6cfkjtsADi7RwKaUb+o oXccBIyGKazzQlqeefis0R/4wpw758zDtMHD+ahmYdL02i3yLA4s1DAl+aODI80d f4pceVxZtQRdztmNkmOLs7wFU30DoDGZhsAc4borL21PjOcQbi15zvTn35OxCht6 PtecbHBbHoEcklcgXt0Zqj09uPs0Lq3ZKjAbWHvwXHGwuydgEZdk6Zf//uvFzj0l 4NMboxRT9clcn22Gu4GG5LoJkmW0ADlZwWye10OgOvcDdb239IzSWed/ILn6QKYk tWwve6a2STV3bsQTZx3TEYVFWxj9cSQXu2LVK2u1KUZnDHNk/VQIgM/cYUpcsAo0 9kkRpJE7G7nMYTS10g2e2mxUfUSGV9qTRF7uxKs/mLqXXHXVQr5in/diYV1mUAIy 7oC41i01IgdrYsSgCuQYZqKF3xAd5yM35kOk3opDeK1BMC9jFqCoUjQKZhIhwlLh p+jwKLAofIeKJkLUdaBMOX0EG9IFbCCmcQcdiN5ep5dAqXHLGJ1m8fzeTX50ayzB TFD+AWhBX/R+JNwP0GVUq3vazS3w6EAVne3vvazY/MHZ+ypNWEZq+6FypF76ZaCO QDmEhDRwDauEVYP2cMw0 =0BTo -----END PGP SIGNATURE----- --8A1KLgNfQFCaHvELhO3Nisp2nN16jL0vd--