Re: Semi-Pseudo Data Types & Procedure Arguments

From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Semi-Pseudo Data Types & Procedure Arguments
Date: 2013-06-26 15:18:09
Message-ID: 20130626151809.GA4024@hermes.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 26, 2013 at 01:50:46AM -0400, Joshua Burns wrote:

> Example #1:
> -- A stored procedure which can accept two arguments, each of which could
> be text, character varying, character varying(any length) or character(any
> length).
> SELECT * FROM my_fn('val1'::text, 'val2'::character(4));
>
> Example #2:
> -- A stored procedure which can accept two arguments, each of which could
> be smallint, integer, or bigint.
> SELECT * FROM my_fn('1'::smallint, '3726323626326262362'::bigint);

...

> In regards to Examples 1 & 2, I'm at a complete loss.

I suppose you can use function overloading.

Have only the "base" function (that which operates on the
"largest" type, say TEXT/BIGINT) contain the actual code and
write wrappers in the SQL PL (not plpgsql) which accept
other types and cast towards TEXT and BIGINT as needed.

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rory Campbell-Lange 2013-06-26 15:18:55 Re: array_agg and partition sorts
Previous Message Alban Hertroys 2013-06-26 14:58:53 Re: utf8 errors