Re: Semi-Pseudo Data Types & Procedure Arguments

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joshua Burns <jdburnz(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Semi-Pseudo Data Types & Procedure Arguments
Date: 2013-06-26 15:27:12
Message-ID: 7496.1372260432@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua Burns <jdburnz(at)gmail(dot)com> writes:
> Has anyone played around with what I would call "Semi-Pseudo Data Types,"
> in which a stored procedure may accept a sub-set of a Pseudo Data Types but
> not just any pseudo data-type, such as any type of string (text, character
> varying, character), any type of integer (smallint, integer, bigint), or a
> single element or an array of elements?

Well, you can already handle such scenarios, no? Just accept text, or
bigint, and let the existing implicit conversions handle the other
cases.

> -- A stored procedure which can accept two argument, which can be a single
> integer field, or an array of integers.

Those two cases seem unlikely to be supportable by the same
implementation, so it seems more likely that what you'd be doing is just
overloading the function name with two instances, my_fn(int) and
my_fn(int[]).

Another trick that's often used is to use an implementation that isn't
quite as general as the signature might suggest. For example consider

create function my_add(anyelement, anyelement) returns anyelement as
'select $1 + $2' language sql;

This will work for any data type that has a "+" operator, which is a
smaller scope than the "anyelement" signature implies. Of course this
particular function is pretty useless compared to just writing "+", but
perhaps the idea will help you.

Anyway, I can't see much value in inventing "anystring" or "anyint".
The former is not distinguishable from "text" at all. The latter might
have some micro-efficiency gain compared to using "bigint", but probably
not enough to be worth the trouble.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-06-26 15:29:22 Re: Need help compiling from souce
Previous Message Rory Campbell-Lange 2013-06-26 15:18:55 Re: array_agg and partition sorts