Received: from bjke.com (firewall-user@ganymede.bjke.com [144.210.8.38]) by hub.org (8.8.8/8.7.5) with ESMTP id OAA15459 for ; Mon, 8 Jun 1998 14:13:01 -0400 (EDT) Received: by bjke.com; id OAA20244; Mon, 8 Jun 1998 14:10:42 -0400 (EDT) Received: from cpsmail.cpsgroup.com(144.210.12.11) by gauntlet.bjke.com via smap (3.2) id xmaa19764; Mon, 8 Jun 98 14:10:06 -0400 Received: by cpsmail with Internet Mail Service (5.0.1458.49) id ; Mon, 8 Jun 1998 13:12:23 -0500 Message-ID: From: "Jackson, DeJuan" To: Nicolas.Caillaud@mail.dotcom.fr, pgsql-sql@postgreSQL.org Subject: RE: [SQL] getting the values of a complex attribute Date: Mon, 8 Jun 1998 13:12:21 -0500 X-Priority: 3 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1458.49) Content-Type: text/plain > Hi * > > I'm new to SQL, and being in the Linux world, I began with Postgresql. > One day, I wrote the following : > > - create table person (name text); > - create table book(name text, author person); > > simple, isn't it ? ;() sure... > Now : > > - insert into person (name) values ('nicolas'); > INSERT 691704 1 > - insert into person (name) values ('julien'); > INSERT 691705 1 > > now, to fill book : > - insert into book (name, author) values ('my book', 691704); > INSERT 691706 1 > > ok, but cant i write anything but the oid of the person record i want > to > insert ? (this is my first question) Not in that table definition. > Next : > insert into book (name,author) values ('other ', 691705); > INSERT 691707 > > OK, right now, i want te get all books written by 'nicolas', i want to > write > > select * from book where author.name = 'nicolas'; > > ERROR: author: Table does not exist. > > select * from book where author = 691706; > > ERROR: There is no operator '=' for types 'person' and 'int4' > You will either have to retype this query using an explicit > cast, > or you will have to define the operator using CREATE OPERATOR > try: select * from book where EXISTS(select person.oid from person where person.oid = book.author and person.name = 'nicolas'); or select book.* from book, person where book.author = person.oid and person.name = 'nicolas'; use the faster one. > Now my second question : what can i do to get (in a simpler manner) > all the books written by 'nicolas' ? > > I think that writing an operator just to do that is a little bit > complicated :-(( > > Thank you if someone got the answer ....... > > -- > Nicolas Caillaud > Nicolas.Caillaud@mail.dotcom.fr > > >