Re: [GENERAL] Get user defined type OID (PostgreSQL extension in C)

2017-08-25 Thread Peter Eisentraut
On 8/25/17 14:34, Fabiana Zioti wrote:
> I'm developing an extension to PostgreSQL using C. I created a
> user-defined type called geo_trajc_elem. I also created a function to
> generate an array of this new type.

> In this case, it is not possible to use get_fn_expr_argtype because I am
> not passing the new type as argument but creating it in the function
> itself, correct ?

The array type for a base type is automatically created by CREATE TYPE.
So the type is already there.

What you are (possibly) doing is constructing a value of that array
type.  But then the OIDs of all the types involved don't change, and you
can use the standard functions to look up the types of your arguments
and the associated array types.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Get user defined type OID (PostgreSQL extension in C)

2017-08-25 Thread Melvin Davidson
On Fri, Aug 25, 2017 at 2:34 PM, Fabiana Zioti 
wrote:

>
> I'm developing an extension to PostgreSQL using C. I created a
> user-defined type called geo_trajc_elem. I also created a function to
> generate an array of this new type.
>
>
> ()
>
>   ArrayType *result_array;
>   struct geo_trajc_elem *traje = (struct geo_trajc_elem
> *)palloc(sizeof(struct geo_trajc_elem));
>
>   Timestamp time_el = PG_GETARG_TIMESTAMP(1);
>   struct geo_point *pt = PG_GETARG_GEOPOINT_TYPE_P(2);
>
>   int16 typlen;
>   bool typbyval;
>   char typalign;
>
>   Datum datum_element;
>
>
>   traje = DatumGetGeoTrajETypeP(DirectFunctionCall2(get_trajectory_elem,
> PointerGetDatum(time_el), PointerGetDatum(pt)));
>   datum_element = PointerGetDatum(traje);
>
>   /* Oid element_type = get_fn_expr_argtype(fcinfo->flinfo, 0); */
>
>   Oid element_type = ?
>
>   get_typlenbyvalalign(element_type, , , );
> ()
>
>
> Is there a function to get the id of my new type? Like get_oid_elem
> (struct geo_trajc_elem)
>
> In this case, it is not possible to use get_fn_expr_argtype because I am
> not passing the new type as argument but creating it in the function
> itself, correct ?
>

*>Is there a function to get the id of my new type? Like get_oid_elem
(struct geo_trajc_elem)*

*A simple*

*SELECT oid, typname*
* FROM pg_type*
* WHERE typname = 'struct geo_trajc_elem';*

*should do the trick for you.*

-- 
*Melvin Davidson*
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.