Skip site navigation (1) Skip section navigation (2)

Re: [QUESTIONS] using composite types

From: Brian Grossman <brian(at)SoftHome(dot)net>
To: Peter T Mount <postgresdev(at)maidast(dot)demon(dot)co(dot)uk>
Cc: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>, pgsql-questions(at)postgresql(dot)org, Postgres Hackers List <hackers(at)postgresql(dot)org>
Subject: Re: [QUESTIONS] using composite types
Date: 1998-03-15 23:50:15
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
> On Fri, 13 Mar 1998, Thomas G. Lockhart wrote:
> > > How can I use composite types?
> > > If I create two tables like this:
> > >         create table A ( a int, b int);
> > >         create table D ( a A, b int);
> > > I would expect to be able to
> > >         insert into D (a.a, a.b, b) values (1,2,3);
> > > and
> > >         select a.a, a.b, b from D;
> > > That doesn't work, at least not with postgresql 6.3.  Is that the way
> > > it's supposed to work?  What is the proper way to do it?
> I've just tried it here, and it seems that the value to insert into D is
> the OID of a row in table A.
> > I'm not sure if this is supported. The old tutorial does not have an
> > example exactly like this (at least that I could find), but it seems
> > like it _should_ work, and the backend accepts the syntax.
> > 
> > What you want to do can probably be accomplished with inheritance, but
> > that only seems to work if you have unique names for more of your
> > fields:
> > 
> >   create table A ( a int, b int);
> >   create table D ( c int) inherits (A);
> > 
> But, if you try
> > 
> >   create table D ( b int) inherits (A);
> > 
> > then the new column in D gets lost without warning!

> This would give a table based on the parent table, but I think he was
> trying to use table D to refer to values in table A _as_ a type.

Yes, I am trying to use A as a type.  I was hoping there was some syntax
sugar that I was missing; the C-like struct traversal syntax would have
been nice, but oh well.  I see how an oid could work, but the idea was to
make my life as a programmer easier.  I'll just prepend the A_ to a and b
in A and inherit, so I can "select A_a, A_b, b from D".  I got lucky and
all my prefixed names fit in under the 32 character name limit.


pgsql-hackers by date

Next:From: Brett McCormickSDate: 1998-03-16 00:46:54
Subject: datetime default 'now' broken?
Previous:From: Maurice GittensDate: 1998-03-15 17:07:12
Subject: Re: [QUESTIONS] Re: [HACKERS] text should be a blob field

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group