Received: from mx99.openu.ac.il (arbel.openu.ac.il [147.233.32.4]) by hub.org (8.9.3/8.9.3) with ESMTP id GAA19447 for ; Mon, 26 Jul 1999 06:27:23 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from talmon.openu.ac.il (talmon.openu.ac.il [147.233.32.11]) by mx99.openu.ac.il (Postfix) with ESMTP for id 6C7C84B579; Mon, 26 Jul 1999 13:27:22 +0300 (IDT) Received: from [147.233.159.109] (mac-herouth.pc.openu.ac.il) by talmon.openu.ac.il (Netscape Messaging Server 3.54) with ESMTP id AAA5A for ; Mon, 26 Jul 1999 13:30:39 +0300 X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <199907260452.VAA30904@uno.tksoft.com> References: from "Herouth Maoz" at Jul 25, 99 03:47:58 pm Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Mon, 26 Jul 1999 13:27:58 +0300 To: pgsql-sql@postgresql.org From: Herouth Maoz Subject: Re: [SQL] Expr Abbreviations/Functions? At 07:52 +0300 on 26/07/1999, tjk@tksoft.com wrote: > If I recall the original question correctly, the > "only" real solution would seem to be to define > a function to search the appropriate fields. Yes. The original question had a conceptual problem. It wanted to abbreviate the expression without the name of the table. This was nonsensical - you can't ask whether id > 3. You can ask whether person.id > 3. Just "id" could be anything in the world. Asking a database to do that is like asking a person to play a flute in vacuum. Another problem was that it implied returning a set of rows. This is not well supported by postgres - and that's a known limitation. The best thing that can be done at the moment is to have a function that accepts the strings as parameters and returns a boolean: CREATE FUNCTION match_three ( text, text, text, text ) RETURNS bool AS ' SELECT (( $1 ~ $4 ) OR ( $2 ~ $4 ) OR ($3 ~ $4)) ' LANGUAGE 'sql'; Then it can be used as: SELECT * FROM table1 WHERE match_three( x1, x2, x3, 'foo' ); Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma