Re: Mysterious Bus Error with get_fn_expr_argtype() - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: Mysterious Bus Error with get_fn_expr_argtype()
Date
Msg-id 608558AF-5A68-4966-B70D-54EECDAF88E9@kineticode.com
Whole thread Raw
In response to Re: Mysterious Bus Error with get_fn_expr_argtype()  ("David E. Wheeler" <david@kineticode.com>)
Responses Re: Mysterious Bus Error with get_fn_expr_argtype()  ("David E. Wheeler" <david@kineticode.com>)
Re: Mysterious Bus Error with get_fn_expr_argtype()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Sep 2, 2008, at 08:58, David E. Wheeler wrote:

> On Sep 1, 2008, at 22:31, Brendan Jurd wrote:
>
>>> Oh, another thing: it shouldn't be STRICT.  Nulls have perfectly  
>>> good
>>> types.
>>
>> Agreed.
>>
>> Barring any further comments/objections, I'll go ahead and prepare a
>> patch to add this to core.
>
> So it will return a text representation or an Oid?

Looks like regtype displays as an integer. So how about pg_regtypeof()  
and pg_typeof()?

PG_FUNCTION_INFO_V1(pg_regtypeof);

Datum
pg_regtypeof(PG_FUNCTION_ARGS)
{    PG_RETURN_OID(get_fn_expr_argtype(fcinfo->flinfo, 0));
}

PG_FUNCTION_INFO_V1(pg_typeof);

Datum
pg_typeof(PG_FUNCTION_ARGS)
{    Oid    typeoid;
    typeoid = get_fn_expr_argtype(fcinfo->flinfo, 0);    if (typeoid == InvalidOid) {        ereport(            ERROR,
(               errcode(ERRCODE_FEATURE_NOT_SUPPORTED),                errmsg("could not determine data type of
argumentto  
 
pg_typeof()")            )        );    }
PG_RETURN_DATUM(CStringGetDatum(format_type_be(typeoid)));
}

Best,

David



pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Mysterious Bus Error with get_fn_expr_argtype()
Next
From: "David E. Wheeler"
Date:
Subject: Re: Mysterious Bus Error with get_fn_expr_argtype()