Re: Problem with self-made plpgsql-function / casting

From: Moritz Bayer <moritz(dot)bayer(at)googlemail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Problem with self-made plpgsql-function / casting
Date: 2005-08-20 16:04:06
Message-ID: c244500b0508200904311f10cc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 on
it!

2005/8/20, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
> Moritz Bayer <moritz(dot)bayer(at)googlemail(dot)com> 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
>
> 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 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:
>
> select fc_editlanguage(42, 'foo', 'bar', 1::smallint);
>
> This is enough of a notational pain in the neck that it's easier just to
> declare the argument as integer.
>
> regards, tom lane
>

--
<img src="http://ad.zanox.com/ppv/?2510394C569771607" align="bottom"
width="1" height="1" border="0" hspace="1"><a href="
http://ad.zanox.com/ppc/?2510394C569771607T">Lenscare AG - Europas größter
Kontaktlinsenversand</a>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Postgres Admin 2005-08-20 17:17:55 Data insert
Previous Message Moritz Bayer 2005-08-20 16:00:18 Re: Problem with self-made plpgsql-function / casting