X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 72C369DCA3B for ; Sun, 5 Mar 2006 11:24:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25738-05 for ; Sun, 5 Mar 2006 11:24:11 -0400 (AST) X-Greylist: delayed 00:07:16.050844 by SQLgrey- Received: from puntd5.cc.uga.edu (puntd5.cc.uga.edu [128.192.1.108]) by postgresql.org (Postfix) with ESMTP id DC31A9DCA2C for ; Sun, 5 Mar 2006 11:24:04 -0400 (AST) Received: from uga.edu (cantor.english.uga.edu [128.192.25.103]) by puntd5.cc.uga.edu (MOS 3.5.9-GR) with SMTP id CPV36871 (AUTH via LOGINBEFORESMTP); Sun, 5 Mar 2006 10:16:52 -0500 (EST) Received: by uga.edu (sSMTP sendmail emulation); Sun, 5 Mar 2006 10:16:52 -0500 Date: Sun, 5 Mar 2006 10:16:52 -0500 From: sramsay@uga.edu To: pgsql-sql@postgresql.org Subject: functions in WHERE clause Message-ID: <20060305151652.GA14216@cantor.english.uga.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-PGP-Key: http://cantor.english.uga.edu/pubkey.asc User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.55 required=5 tests=[NO_REAL_NAME=0.55] X-Spam-Score: 0.55 X-Spam-Level: X-Archive-Number: 200603/93 X-Sequence-Number: 24439 Hi All, I've got one of these: SELECT * from some_table WHERE test_for_equality_is_syntactically_ugly; What I'd like to do is encapsulate the WHERE clause in a function, but I'm having no end of trouble. The WHERE clause expects the function to return a boolean value. I can certainly return a boolean value from a function, but here it seems to me that what the function really has to do is return a set of boolean values -- the test in the WHERE clause sometimes evaluates to true and sometimes evaluates to false, and that is in turn used to constrain the query results. But you can't return a set of anything (I don't think) in a WHERE clause, because it seems to want a singular boolean value. Is it possible to do what I'm trying to do? I've written a few simple sql and pl/pgsql functions over the years, but I'm no expert. Perhaps I'm barking up the wrong tree here. It seems like what I really need is a way to have some kind of rewrite rule (e.g. when you see "foo(x)" substitute ugly string). Sort of like a Lisp macro ;) Steve -- Stephen Ramsay Assistant Professor Department of English University of Georgia email: sramsay@uga.edu web: http://cantor.english.uga.edu/ PGP Public Key ID: 0xA38D7B11