Re: user defined data types - help

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Sathish Vadhiyar <vss(at)cs(dot)utk(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: user defined data types - help
Date: 2002-09-13 22:57:44
Message-ID: 20020914085744.A3048@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Why are you trying to store this all into one value? Why not just create two
tables, one for the names of the machines and one to stores the bandwidths?

On Fri, Sep 13, 2002 at 11:39:23AM -0400, Sathish Vadhiyar wrote:
>
> Hi.
>
> I have a struct in C in my application program.
>
> typedef struct{
> int count;
> char** machine_names;
> double* bandwidth;
> } MACHINEINFO;
>
> 'count' is the number of machines. machine_names[i] gives the machine name
> of machine i. 'bandwidth' is a matrix that stores bandwidth information
> between the machines. So bandwidth[i*count+j] gives the bandwidth between
> machines i and j.
>
> Iam trying to define a corresponding structure and define the type to
> store in a postgresql datat base using 'CREATE TYPE'.
>
> I don't want to have a structure like
>
> typedef struct{
> int32 size; /* for variable length */
> int4 count;
> char data[1];
> } PSQLSTRUCT;
>
> and have both the machine_names and bandwidth encoded into string stored
> in 'data'.
>
> What I would like instead is something like a 'polygon' type where I would
> have.
>
> typedef struct{
> char machine_name[100]; /* Ideally, I don't want to fix the size of a
> single machine as 100. But I will compromise
> for the moment */
> float8 bandwidth; /* ???? */
> } SINGLEMACHINE
>
> typedef struct{
> int32 size;
> int4 count;
> SINGLEMACHINE sm[1]; /* variable number of machines */
> } PSQLSTRUCT;
>
> This is similar to the POLYGON built in type where the structure polygon
> consists of variable number of POINT structures.
>
> But here is the tricky issue. Unlike the POINT structure that contains
> fileds of fixed lengths, my SINGLEMACHINE structure consists of variable
> length field in 'bandwidth'.
>
> Any ideas regarding how to do this?
>
>
> Thanks.
>
> ---------------------------------------------------------------------
>
> Sathish S. Vadhiyar
> PhD Candidate Research Assistant, Innovative Computing Laboratory
> Computer Science Department
> University of Tennessee
> Knoxville
>
> Ph: (865)946-4558 (H) , (865)974-6323 (O).
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message jaya prakash 2002-09-13 23:02:42 table creation error
Previous Message Stephan Szabo 2002-09-13 22:24:12 Re: cascading