agora inbox for postgres@postgres.berkeley.edu
help / color / mirror / Atom feedFrom: Robert Patrick <Robert_Patrick@RASAM.NDIM.EDRC.CMU.EDU>
To: postgres@postgres.Berkeley.EDU
Subject: Re: retrieve query
Date: Mon, 06 Mar 1995 21:25:24 -0500
Message-ID: <199503070226.SAA01078@nobozo.CS.Berkeley.EDU> (raw)
> I have two classes: one with info about institutions and second with their
> phone numbers (and with institution id). How should I write query which
> returns institution name and phone number ? I need name even if there is
> no phone number for it. Simple :
> retrieve (i.name, ph.number) where i.id=ph.id
> returns only those instances from i which has matching entry in ph.
Actually, the only way to do this without restructuring your tables is to
define a function. Here's how you would do it:
rasam.ndim.edrc.cmu.edu> monitor rp2y_test
Welcome to the POSTGRES terminal monitor
Go
* create info(id=int4, name=text)\g
Query sent to backend is "create info(id=int4, name=text)"
CREATE
Go
* create phone(id=int4, number=text)\g
Query sent to backend is "create phone(id=int4, number=text)"
CREATE
Go
* define function getPhoneNumber
(language = "postquel", returntype = text)
arg is (int4)
as "retrieve (phone.number) where phone.id = $1"\g
Query sent to backend is "define function getPhoneNumber (language =
"postquel", returntype = text) arg is (int4) as "retrieve
(phone.number) where phone.id = $1""
DEFINE
Go
* append info( id = 1, name="CMU")\g
Query sent to backend is "append info( id = 1, name="CMU")"
APPEND 38080
Go
* append info(id=2, name = "MIT")\g
Query sent to backend is "append info(id=2, name = "MIT")"
APPEND 38081
Go
* append phone(id =2, number="234-5678")\g
Query sent to backend is "append phone(id =2, number="234-5678")"
APPEND 38082
Go
* retrieve(info.id, num = getPhoneNumber(info.id))\g
Query sent to backend is "retrieve(info.id, num = getPhoneNumber(info.id))"
-----------------------------
| id | num |
-----------------------------
| 1 | |
-----------------------------
| 2 | 234-5678 |
-----------------------------
Go
*
Robert
--
+------------------------------------------------------------------------+
| Robert Patrick (rp2y+@edrc.cmu.edu) Engineering Design Research Center |
| n-dim Group Carnegie Mellon University |
| World Wide Web: http://paneer.ndim.edrc.cmu.edu:8888/~rp2y/Home.html |
+------------------------------------------------------------------------+
==============================================================================
To add/remove yourself to/from the POSTGRES mailing list: send mail with
the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU".
If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
a human will deal with it. DO NOT post to the "postgres" mailing list.
==============================================================================
URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres/
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: postgres@postgres.berkeley.edu
Cc: Robert_Patrick@RASAM.NDIM.EDRC.CMU.EDU
Subject: Re: retrieve query
In-Reply-To: <199503070226.SAA01078@nobozo.CS.Berkeley.EDU>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox