Search Postgresql Archives

Re: [NOVICE] Convert Datum to an user-defined data type?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 10, 2014 at 11:09 PM, Anh Pham <atpham.wpi@xxxxxxxxx> wrote:
> Hi everyone,
> I have created a new data types using SQL in a database:
>
> CREATE TYPE type1 AS (
> score integer,
> time integer[],
> );
>
> I also created a server extension module (C code), and I was able to
> retrieve a Datum value of type1 from the database (using SPI_ functions)
> My question is: how can I convert that Datum value back to type1 data
> structure (in C code), so I can easily deal with score and time values?
>

I wonder if you read section 35.9.8 about using "funcapi.h" here:
http://www.postgresql.org/docs/9.1/static/xfunc-c.html

I suggest you read more about the following functions and how they are
to be used (quoting brief descriptions from the page here):

* To get a TupleDesc based on a type OID, call:
TupleDesc TypeGetTupleDesc(Oid typeoid, List *colaliases)

* Once you have a TupleDesc, call:
TupleDesc BlessTupleDesc(TupleDesc tupdesc)

* With the blessed tupdesc, given user data in Datum form, to build a
HeapTuple, use:
HeapTuple heap_form_tuple(TupleDesc tupdesc, Datum *values, bool *isnull)

--
Amit


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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux