1

I was not able to find neither in the documentation nor in any stack exchange forum how to create in PostgreSQL a user-defined pseudo-type. I am defining temporal types (i.e., types that vary over time) and the subtypes of the temporal types can be Boolean, integer, float, etc. In some sense, temporal types share some similarities with range types.

In the same way that there is a pseudo-type anyrange, I would like to define a pseudo-type anytemporal. After defining the input and output functions for anytemporal in C as follows

PG_FUNCTION_INFO_V1(anytemporal_in);

Datum
anytemporal_in(PG_FUNCTION_ARGS)
{
    ereport(ERROR,
            (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
             errmsg("cannot accept a value of type %s", "anytemporal")));

    PG_RETURN_VOID();           /* keep compiler quiet */
}

PG_FUNCTION_INFO_V1(anytemporal_out);

PGDLLEXPORT Datum
anytemporal_out(PG_FUNCTION_ARGS)
{
    return temporal_out(fcinfo);
}

I defined the corresponding functions in SQL as follows

CREATE FUNCTION anytemporal_in(cstring, oid, integer)
    RETURNS anytemporal
    AS 'MODULE_PATHNAME'
    LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION anytemporal_out(anytemporal)
    RETURNS cstring
    AS 'MODULE_PATHNAME'
    LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE TYPE anytemporalinst (
    internallength = variable,
    input = anytemporal_in,
    output = anytemporal_out,
    storage = extended,
    alignment = double
);

Now that the pseudo-type is created I inspect the catalog as follows

select typname, typlen, typbyval, typtype, typcategory 
from pg_type 
where typname = 'anytemporal' or typname = 'anyrange'

'anyrange',-1,false,'p','P'
'anytemporal',-1,false,'b','U'

How to tell PostgreSQL that anytemporal is a pseudo-type so that the typtype and the typcategory should be marked, respectively, as 'p' and 'P' ?

Esteban Zimanyi
  • 201
  • 3
  • 6

0 Answers0