Thread: Query

Query

From
"Atul"
Date:
Hi,
 
I have a query regarding composite types (user-defined types). I have defined a type alongwith its input and output functions. But I am not able to access the type using my PL/pgSQL function. My type is as follows
 
typedef struct Sample
{
    int nCtr1,
    int nCtr2
} Sam;
 
If anyone has some clue about it please mail back.
 
My email-id is atulk@newgen.co.in 

Re: Query

From
"Eric G. Miller"
Date:
On Fri, Apr 06, 2001 at 06:57:03PM +0530, Atul wrote:
> Hi,
>
> I have a query regarding composite types (user-defined types). I have
> defined a type alongwith its input and output functions. But I am not
> able to access the type using my PL/pgSQL function. My type is as
> follows
>
> typedef struct Sample { int nCtr1, int nCtr2 } Sam;
>
> If anyone has some clue about it please mail back.

PL/PgSQL is not going to be able to look into your structure if that's
what you want.  PostgreSQL treats such things as blobs of memory.  You
might define accessor functions though...

int4
SampleGetnCtr1 (Sam *s)
{
    return s->nCtr1;
}

Etc...

Then, maybe, you can call the function(s) to get/set it's parts...

SELECT sample_get_ctr1(mysample) INTO foo FROM ... ;

--
Eric G. Miller <egm2@jps.net>