Re: Initializing Datums for use with SPI_execute_plan

From: Andrew - Supernews <andrew+nonews(at)supernews(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Initializing Datums for use with SPI_execute_plan
Date: 2006-09-18 19:47:15
Message-ID: slrnegttu3.2ea3.andrew+nonews@atlantis.supernews.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2006-09-18, "Jack Orenstein" <jack(dot)orenstein(at)gmail(dot)com> wrote:
> On 9/14/06, Andrew - Supernews <andrew+nonews(at)supernews(dot)com> wrote:
>> One way:
>
> Thank you, I hope you can help with some clarifications.
>
>>
>> bytea *my_bytea = (bytea *) palloc(byte_array_len + VARHDRSZ);
>> memcpy(VARDATA(my_bytea), byte_array, byte_array_len);
>> VARATT_SIZEP(my_bytea) = byte_array_len + VARHDRSZ;
>>
>> values[0] = DirectFunctionCall1(textin,CStringGetDatum(yourstring));
>
> What is textin -- the name of a function?

textin is the name of the input function for the "text" type; it takes a
C string as input and returns a Datum. Most (but not all) type input
functions can be called this way. (The format of the C string that you pass
to a type input function is exactly the same as you'd send from a client,
without quoting/escaping.)

(The ones that can't be called by DirectFunctionCall1 are those that need
access to type info, such as array or composite value input, or user-defined
types. Those are callable using other fmgr interfaces.)

>> values[1] = PointerGetDatum(my_bytea);
>
> One other thing is still unclear: What about signed/unsigned long? If
> I have a C long, then how do I get a Datum that I can assign to
> values[i]?

What matters isn't so much the C type that you have, as the SQL type that
you are supposedly providing. Pg doesn't have an "unsigned" type unless
you created your own, so the question is, are you passing an int4 or an
int8 to SQL?

--
Andrew, Supernews
http://www.supernews.com - individual and corporate NNTP services

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message timasmith 2006-09-18 20:06:09 Upgrading schemas
Previous Message Volkan YAZICI 2006-09-18 19:17:46 Re: psql memory usage when creating delimited files