X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 17F7652EAE for ; Sat, 20 Aug 2005 13:04:15 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05379-05 for ; Sat, 20 Aug 2005 16:04:08 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.202]) by svr1.postgresql.org (Postfix) with ESMTP id C929A52CD2 for ; Sat, 20 Aug 2005 13:04:06 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id z6so527080nzd for ; Sat, 20 Aug 2005 09:04:06 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=googlemail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=qjMa4LnUyJNFwN10FGC2+5nvgW506SGWZnUKY1hej/B+aMCVtb2OVAOUVWi7Fms1YTmZShArtz1u43XxYKEDmrZdlk/xu5W5PMrjkjUGa0pHIsWQsFlSmxHmXvStpyGAbcrSG7KLrQKI3SxZ4C1hSZGUTgE2914wBwYlS12upkA= Received: by 10.36.37.17 with SMTP id k17mr3182917nzk; Sat, 20 Aug 2005 09:04:06 -0700 (PDT) Received: by 10.36.247.65 with HTTP; Sat, 20 Aug 2005 09:04:06 -0700 (PDT) Message-ID: Date: Sat, 20 Aug 2005 18:04:06 +0200 From: Moritz Bayer To: Tom Lane Subject: Re: Problem with self-made plpgsql-function / casting Cc: pgsql-sql@postgresql.org In-Reply-To: <24394.1124553118@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5577_18906637.1124553846325" References: <24394.1124553118@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.325 required=5 tests=[AWL=0.214, HTML_40_50=0.086, HTML_MESSAGE=0.001, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/178 X-Sequence-Number: 22406 ------=_Part_5577_18906637.1124553846325 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline That's it!!! Thanks a lot! Moritz PS: Hope some day I'll be the one to be an help for newbies! I'm working o= n=20 it!=20 2005/8/20, Tom Lane :=20 >=20 > Moritz Bayer writes: > > ERROR: function public.fc_editlanguage(integer, "unknown", "unknown", > > integer) does not exist > > > > CREATE OR REPLACE FUNCTION "public"."fc_editlanguage" (id bigint, name > > varchar, kuerzel varchar, active smallint) RETURNS smallint AS >=20 > The short answer to this is to avoid declaring function arguments as > "smallint". When you call this as, say, >=20 > select fc_editlanguage(42, 'foo', 'bar', 1); >=20 > the "42" and the "1" are initially typed as integer constants. There's > an implicit up-cast from integer to bigint, so the parser has no problem > matching the 42 to a bigint parameter, but the down-cast from integer to > smallint is not implicit. With the function as written you'd have to > cast to smallint explicitly: >=20 > select fc_editlanguage(42, 'foo', 'bar', 1::smallint); >=20 > This is enough of a notational pain in the neck that it's easier just to > declare the argument as integer. >=20 > regards, tom lane >=20 --=20 Lenscare AG - Europas gr=F6=DF= ter=20 Kontaktlinsenversand ------=_Part_5577_18906637.1124553846325 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
That's it!!!
Thanks a lot!
 
Moritz
 
PS: Hope some day I'll be the one to be an help for newbies! I'm worki= ng on it! 

 
2005/8/20, Tom Lane <tgl@sss.pgh.pa.us>:
Moritz Bayer <moritz.bayer@googlemail.com> writes:=
>  ERROR: function public.fc_editlanguage(integer, "unkno= wn", "unknown",
> integer) does not exist
>
&= gt; CREATE OR REPLACE FUNCTION "public"."fc_editlanguage&quo= t; (id bigint, name
> varchar, kuerzel varchar, active smallint) RETURNS smallint AS
=
The short answer to this is to avoid declaring function arguments as"smallint".  When you call this as, say,

 =       select fc_editlanguage(42, 'foo', 'bar', 1);

the "42" and the "1" are initially typed as int= eger constants.  There's
an implicit up-cast from integer to b= igint, so the parser has no problem
matching the 42 to a bigint paramete= r, but the down-cast from integer to
smallint is not implicit.  With the function as written you'd= have to
cast to smallint explicitly:

    &nb= sp;  select fc_editlanguage(42, 'foo', 'bar', 1::smallint);

Thi= s is enough of a notational pain in the neck that it's easier just to
declare the argument as integer.

     &= nbsp;           &nbs= p;     regards, tom lane


=
--
<img src=3D"http://ad.zanox.com/ppv/?2510394C569771607 " align=3D"bottom" width=3D"1" height=3D"= 1" border=3D"0" hspace=3D"1"><a href=3D"= ;http://ad.za= nox.com/ppc/?2510394C569771607T" >Lenscare AG - Europas gr=F6=DFter Kontaktlinsenversand</a>=20 ------=_Part_5577_18906637.1124553846325--