From: Tom Lane <tgl@sss.pgh.pa.us>
To: Moritz Bayer <moritz.bayer@googlemail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Problem with self-made plpgsql-function / casting
Date: Sat, 20 Aug 2005 11:51:58 -0400
Message-ID: <24394.1124553118@sss.pgh.pa.us> (raw)
In-Reply-To: <c244500b0508200754193958c7@mail.gmail.com>
References: <c244500b0508200754193958c7@mail.gmail.com>
Moritz Bayer <moritz.bayer@googlemail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, moritz.bayer@googlemail.com
Subject: Re: Problem with self-made plpgsql-function / casting
In-Reply-To: <24394.1124553118@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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