PostgreSQL如何创建用户定义的伪类型

时间:2017-12-23 13:14:22

标签: postgresql types user-defined

我无法在文档或任何堆栈交换论坛中找到如何在PostgreSQL中创建用户定义的伪类型。我定义了时间类型(即随时间变化的类型),时间类型的子类型可以是布尔,整数,浮点等。在某种意义上,时间类型与范围类型有一些相似之处。

与伪类anyrange的方式相同,我想定义一个伪类型anytemporal。在C中定义anytemporal的输入和输出函数后,如下所示

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

我在SQL中定义了相应的函数,如下所示

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

现在创建了伪类型,我按如下方式检查目录

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'

如何告诉PostgreSQL anytemporal是伪类型,以便typtypetypcategory分别标记为' p'和' P' ?

0 个答案:

没有答案