Semi-Pseudo Data Types & Procedure Arguments - Mailing list pgsql-general

From Joshua Burns
Subject Semi-Pseudo Data Types & Procedure Arguments
Date
Msg-id CAB73KvQBz8RiQxYec6weZTXnyLBuM-Dm4ffyxH-uYAdApNGLdA@mail.gmail.com
Whole thread Raw
Responses Re: Semi-Pseudo Data Types & Procedure Arguments  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Re: Semi-Pseudo Data Types & Procedure Arguments  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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?

The goal would be to define a function in such a way (or perhaps a custom data-type) which constrains to a list of existing data-types. If a custom data-type, then something like "anystring" or "anyint", similar to how the "any", "anyarray" and "anynonarray" pseudo-types already exist.

Here are a few example procedure calls which I'm curious about whether or not they could actually be implemented and if so, efficiently:

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);

Example #3:
-- A stored procedure which can accept two argument, which can be a single integer field, or an array of integers.
SELECT * FROM my_fn(123::integer);
-- Or ...
SELECT * FROM my_fn('{123,456,789}'::integer[])

I have a few ideas in regards to how to accomplish Example #3 without the use of custom data-types, such as setting the procedure's argument to the "any" pseudo data-type and implementing in-procedure logic to reconcile whether the argument is an array or single element, and act accordingly such as throwing the single element into array, to logic wouldn't have to be duplicated.

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

Any thoughts or suggestions are greatly appreciated!

Josh Burns

pgsql-general by date:

Previous
From: dafNi zaf
Date:
Subject: Re: dynamic partitioning
Next
From: Jiří Pavlovský
Date:
Subject: Re: utf8 errors