Getting char * from timestamp in a composite type

From: Michael Akinde <michael(dot)akinde(at)met(dot)no>
To: pgsql-general(at)postgresql(dot)org
Subject: Getting char * from timestamp in a composite type
Date: 2007-12-19 15:40:38
Message-ID: 47693B76.2080105@met.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I need to extract a text string representation of a timestamp from a
user-defined row type; e.g., from the composite type ('1980-01-01
12:00:00', 'Random Comment'), I'd like to extract the C string
1980-01-01 12:00:00 in my user-defined C function.

As I understand it, I should be able to do something like (assuming
"time" is the attribute name):

bool isNull;
HeapTupleHeader t = DatumGetHeapTupleHeader(row);
Datum var = GetAttributeByName( row, "time", & isNull );
// Check for null
char * ret = DatumGetCString( DirectFunctionCall1(textout, var ) );

However, the code above (and every other variant I've tried) invariable
segmentation faults the postmaster. so obviously I am doing something
wrong. Can someone explain (or point to an example that works) of how to
do this?

Regards,

Michael A.

Attachment Content-Type Size
michael.akinde.vcf text/x-vcard 287 bytes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Erik Jones 2007-12-19 15:49:45 Re: thank you
Previous Message Tom Lane 2007-12-19 15:38:52 Re: Password as a command line argument to createuser