Thread: user defined data types - help

user defined data types - help

From
Sathish Vadhiyar
Date:
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).


Re: user defined data types - help

From
Martijn van Oosterhout
Date:
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@postgresql.org so that your
> message can get through to the mailing list cleanly

--
Martijn van Oosterhout   <kleptog@svana.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.

Re: user defined data types - help

From
Sathish Vadhiyar
Date:
Because of 2 reaons:

1. My C structure consists of other such fields like 'latency' etc. Here I
have shown 'bandwidth' for the ease of explaining. Having tables for each
such field will lead to large number of tables and hence will soon get
unmanageable.

2. I have a table in which I want to have this structure as one field.

Thanks.

On Sat, 14 Sep 2002, Martijn van Oosterhout wrote:

> 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@postgresql.org so that your
> > message can get through to the mailing list cleanly
>
> --
> Martijn van Oosterhout   <kleptog@svana.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.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


---------------------------------------------------------------------

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).


Re: user defined data types - help

From
Shridhar Daithankar
Date:
On Sunday 15 September 2002 20:04, Sathish Vadhiyar wrote:
> Because of 2 reaons:
>
> 1. My C structure consists of other such fields like 'latency' etc. Here I
> have shown 'bandwidth' for the ease of explaining. Having tables for each
> such field will lead to large number of tables and hence will soon get
> unmanageable.
>
> 2. I have a table in which I want to have this structure as one field.

You can probably  use array of ints etc. for column types. That may solve one
of your problem..

 HTH

 Shridhar

Re: user defined data types - help

From
Sathish Vadhiyar
Date:
On Sun, 15 Sep 2002, Shridhar Daithankar wrote:

> You can probably  use array of ints etc. for column types. That may solve one
> of your problem..

If I understand you right, I guess you are suggesting to have a table
corresponding to this structure and each field of this table will be array
of doubles for bandwidths, array of doubles for latency, array of text for
machine names etc.

Let us call this table as MACHINETABLE. And let us call the original table
I was mentioning in my previous mail where I want to store this structure
in a field as the BIGTABLE. So, in this scheme, whenever I want to store
the structure in a field in the BIGTABLE, I will insert a row for the
structure in MACHINETABLE and somehow make the field in the BIGTABLE
point to this row.

Is this the kind of thing you had in mind? Is it possible to have a field
in a table point to a row in another table? In that what should be the
type of the field be?

I was originally thinking of creating a type for the structure and define
some operators on it. I guess it is not possible with the kind of
structure I have?

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).


Re: user defined data types - help

From
"Shridhar Daithankar"
Date:
On 15 Sep 2002 at 11:56, Sathish Vadhiyar wrote:
> On Sun, 15 Sep 2002, Shridhar Daithankar wrote:
>
> > You can probably  use array of ints etc. for column types. That may solve one
> > of your problem..
>
> If I understand you right, I guess you are suggesting to have a table
> corresponding to this structure and each field of this table will be array
> of doubles for bandwidths, array of doubles for latency, array of text for
> machine names etc.

Well.. yes.

>
> Let us call this table as MACHINETABLE. And let us call the original table
> I was mentioning in my previous mail where I want to store this structure
> in a field as the BIGTABLE. So, in this scheme, whenever I want to store
> the structure in a field in the BIGTABLE, I will insert a row for the
> structure in MACHINETABLE and somehow make the field in the BIGTABLE
> point to this row.
>
> Is this the kind of thing you had in mind? Is it possible to have a field
> in a table point to a row in another table? In that what should be the
> type of the field be?

Isn't it possible with some kind of referential integrity constraint? Some
id/sequence etc?

Of course fetching a complete row would be a matter to two sql queries now. But
anyway when your data model is broken apart in pieces that's bound to happen//


Bye
 Shridhar

--
The Fifth Rule:    You have taken yourself too seriously.