Re: Internal function call from C-language function

From: Zoltan Boszormenyi <zboszor(at)dunaweb(dot)hu>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Internal function call from C-language function
Date: 2006-12-07 17:01:13
Message-ID: 457848D9.3090208@dunaweb.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Zoltan Boszormenyi írta:
> Hi,
>
> Martijn van Oosterhout írta:
>> On Thu, Dec 07, 2006 at 01:40:22PM +0100, Zoltan Boszormenyi wrote:
>>
>>> text_in() doesn't exists, it's textin() but I have to call it through
>>> DirectFunctionCall1(), like this:
>>>
>>> yeardatum = DirectFunctionCall1(textin, CStringGetDatum("year"));
>>>
>>> However, the session crashes on the subsequent
>>>
>>> returndatum = DirectFunctionCall2(timestamp_part, yeardatum, timest);
>>>
>>
>> It would be a good idea to actually find out where it crashes, that
>> would help you work out what the actual problem is. Just looking at the
>> code you posted, I only see this other bit that looks a bit suspect:
>>
>> Datum timest;
>> bool isnull;
>>
>> t = PG_GETARG_HEAPTUPLEHEADER(0);
>> timest = DatumGetTimestamp(GetAttributeByName(t, "ts_today",
>> &isnull));
>>
>> You're calling DatumGetTimestamp() which would return a timestamp
>> (probably some structure) but you're storing it in a Datum. Just take
>> the result of GetAttributeByName directly.
>>
>
> Thanks, that worked for me.
>
> I have just one more question:
> How can I get an Oid out of a Datum, i.e.
> how do I know what type I get in a given Datum?
> DatumGetObjectId() seems to give me an Oid that
> was specifically stored as a Datum.

I have found the alternative solution.
If t is HeapTupleHeader then:

Oid tupType;
int32 tupTypmod;
TupleDesc tupDesc;

tupType = HeapTupleHeaderGetTypeId(t);
tupTypmod = HeapTupleHeaderGetTypMod(t);
tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);

will give me the needed TupleDesc and I can use SPI_gettypeid().

Thanks and best regards,
Zoltán

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Harris 2006-12-07 17:09:00 Re: pg_controldata output documentation
Previous Message Ragnar 2006-12-07 16:56:53 Re: VACUUM and transactions in different databases