Composite datatypes, dynamic member fields
Composite datatypes, dynamic member fields
От:
Robert Staudinger <r.staudinger@seminarshop.com>
Дата:
Hello,
I'm planning to build some kind of simple object oriented database and
came across PostgreSQL because of it's nearly unlimited ways of
extensibility.
The documentation is really good an I learned a lot about composite
datatypes, how to program them in c, create indices ... from the "Server
Programming" section of the "Developer Manual".
The problem in my case is that I don't know the names of the attributes
beforehand so I can't do a table bases mapping with one table for each
type of object ("class"). So I thought It would maybe be possible to
store the objects always in the same composed datatype - with "dynamic
member fields".
Ok this may be completely insane but ...
Maybe you could just tell me if it's worth to dig deeper.
Robert Staudinger
Re: Composite datatypes, dynamic member fields
От:
Robert Staudinger <robson@stereolyzer.net>
Дата:
> I use inheritance in such a case. > (see INHERITS in CREATE TABLE) > Table with common columns as a base class > and different tables for classes with > inherited base class. > Multiple and multilevel inheritanse possible. The problem in my case is that even a group of objects which belong together might not have even one common attribute. One idea is to implement a . operator on a basic data type and return the value for the corresponding field from the "operator function". E.g. "select * from mytable where mytype.mymember='x'" could call something like mytype_member_read( mytype, member_name ) but I'm not sure which datatype member_name would be in this case. Unfortunately I don't have any idea how to handle updates on such fields with a user defined member access operator yet. Does anybody have any advice on that? Robert Staudinger PS: Please excuse if this explanation doesn't make perfect sense to you - it's a little hard for me to say in English what I mean.
Re: Composite datatypes, dynamic member fields
От:
Robert Staudinger <robson@stereolyzer.net>
Дата:
On Mon, 2002-05-13 at 16:17, Tom Lane wrote:
> Robert Staudinger writes:
> > One idea is to implement a . operator on a basic data type and return
> > the value
> > for the corresponding field from the "operator function".
> > E.g.
> > "select * from mytable where mytype.mymember='x'"
> > could call something like
> > mytype_member_read( mytype, member_name )
> > but I'm not sure which datatype member_name would be in this case.
>
> PG has always had the ability to define functions that could be
> notationally treated as fields. A trivial example:
>
> test72=# create table tours(depart date, return date);
> CREATE
> test72=# insert into tours values('2002-01-01', '2002-01-10');
> INSERT 525275 1
> test72=# insert into tours values('2001-12-15', '2002-01-05');
> INSERT 525276 1
> test72=# create function numdays(tours) returns int as '
> test72'# select $1.return - $1.depart' language sql;
> CREATE
> test72=# select *, tours.numdays from tours;
> depart | return | numdays
> ------------+------------+---------
> 2002-01-01 | 2002-01-10 | 9
> 2001-12-15 | 2002-01-05 | 21
> (2 rows)
>
> The computed field doesn't quite have the same status as real fields
> --- notice that * doesn't know about it in the above example --- but
> it's a useful technique anyway.
>
> regards, tom lane
Hmm I don't know if this solves my problem.
E.g.
I want to store a group of linked objects. Maybe x(ht)ml could be an
example:
| one | two | three |
Re: Composite datatypes, dynamic member fields
От:
"."@babolo.ru
Дата:
Robert Staudinger writes:
> I'm planning to build some kind of simple object oriented database and
> came across PostgreSQL because of it's nearly unlimited ways of
> extensibility.
> The documentation is really good an I learned a lot about composite
> datatypes, how to program them in c, create indices ... from the "Server
> Programming" section of the "Developer Manual".
> The problem in my case is that I don't know the names of the attributes
> beforehand so I can't do a table bases mapping with one table for each
> type of object ("class"). So I thought It would maybe be possible to
> store the objects always in the same composed datatype - with "dynamic
> member fields".
I use inheritance in such a case.
(see INHERITS in CREATE TABLE)
Table with common columns as a base class
and different tables for classes with
inherited base class.
Multiple and multilevel inheritanse possible.
> Ok this may be completely insane but ...
>
> Maybe you could just tell me if it's worth to dig deeper.
>
> Robert Staudinger
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
--
@BABOLO http://links.ru/
Re: Composite datatypes, dynamic member fields
От:
Robert Staudinger <robert.staudinger@fh-sbg.ac.at>
Дата:
> I use inheritance in such a case. > (see INHERITS in CREATE TABLE) > Table with common columns as a base class > and different tables for classes with > inherited base class. > Multiple and multilevel inheritanse possible. The problem in my case is that even a group of objects which belong together might not have even one common attributes. One idea is to implement a . operator on a basic data type and return the value for the corresponding field from the "operator function". E.g. "select * from TABLE where mytype.mymember='x'" could call something like mytype_member_access( mytype, member_name ) Unfortunately I don't have any idea how to handle updates on fields yet. Does anybody have any advice on that? Robert Staudinger PS: Please excuse if this explanation doesn't make much sense to you - it's a little hard for me to say in English what I mean.
Re: Composite datatypes, dynamic member fields
От:
"Ross J. Reedstrom" <reedstrm@rice.edu>
Дата:
On Mon, May 13, 2002 at 10:17:55AM -0400, Tom Lane wrote: > > The computed field doesn't quite have the same status as real fields > --- notice that * doesn't know about it in the above example --- but > it's a useful technique anyway. That particular shortcoming can be overcome by wrapping the computed fields in a view: create view tour_lengths AS select *, tours.numdays from tours; test=# create view tours_plus as select *, tours.numdays from tours; CREATE test=# select * from tours_plus; depart | return | numdays ------------+------------+---------2002-01-01 | 2002-01-10 | 92001-12-15 | 2002-01-05 | 21 (2 rows) Ross
Re: Composite datatypes, dynamic member fields
От:
"."@babolo.ru
Дата:
Robert Staudinger writes:
> On Mon, 2002-05-13 at 16:17, Tom Lane wrote:
> > Robert Staudinger writes:
> > > One idea is to implement a . operator on a basic data type and return
> > > the value
> > > for the corresponding field from the "operator function".
> > > E.g.
> > > "select * from mytable where mytype.mymember='x'"
> > > could call something like
> > > mytype_member_read( mytype, member_name )
> > > but I'm not sure which datatype member_name would be in this case.
> >
> > PG has always had the ability to define functions that could be
> > notationally treated as fields. A trivial example:
> >
> > test72=# create table tours(depart date, return date);
> > CREATE
> > test72=# insert into tours values('2002-01-01', '2002-01-10');
> > INSERT 525275 1
> > test72=# insert into tours values('2001-12-15', '2002-01-05');
> > INSERT 525276 1
> > test72=# create function numdays(tours) returns int as '
> > test72'# select $1.return - $1.depart' language sql;
> > CREATE
> > test72=# select *, tours.numdays from tours;
> > depart | return | numdays
> > ------------+------------+---------
> > 2002-01-01 | 2002-01-10 | 9
> > 2001-12-15 | 2002-01-05 | 21
> > (2 rows)
> >
> > The computed field doesn't quite have the same status as real fields
> > --- notice that * doesn't know about it in the above example --- but
> > it's a useful technique anyway.
> >
> > regards, tom lane
>
> Hmm I don't know if this solves my problem.
> E.g.
> I want to store a group of linked objects. Maybe x(ht)ml could be an
> example:
>
> | one | >two | >three | >
Re: Composite datatypes, dynamic member fields
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Robert Staudinger writes:
> One idea is to implement a . operator on a basic data type and return
> the value
> for the corresponding field from the "operator function".
> E.g.
> "select * from mytable where mytype.mymember='x'"
> could call something like
> mytype_member_read( mytype, member_name )
> but I'm not sure which datatype member_name would be in this case.
PG has always had the ability to define functions that could be
notationally treated as fields. A trivial example:
test72=# create table tours(depart date, return date);
CREATE
test72=# insert into tours values('2002-01-01', '2002-01-10');
INSERT 525275 1
test72=# insert into tours values('2001-12-15', '2002-01-05');
INSERT 525276 1
test72=# create function numdays(tours) returns int as '
test72'# select $1.return - $1.depart' language sql;
CREATE
test72=# select *, tours.numdays from tours; depart | return | numdays
------------+------------+---------2002-01-01 | 2002-01-10 | 92001-12-15 | 2002-01-05 | 21
(2 rows)
The computed field doesn't quite have the same status as real fields
--- notice that * doesn't know about it in the above example --- but
it's a useful technique anyway.
regards, tom lane