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 59A7C9DC841 for ; Sun, 5 Mar 2006 18:22:44 -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 25400-04 for ; Sun, 5 Mar 2006 18:22:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id 671529DC828 for ; Sun, 5 Mar 2006 18:22:42 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1FG1cd-0005iP-00; Sun, 05 Mar 2006 17:22:39 -0500 To: Tom Lane Cc: sramsay@uga.edu, pgsql-sql@postgresql.org Subject: Re: functions in WHERE clause References: <20060305151652.GA14216@cantor.english.uga.edu> <4338.1141581591@sss.pgh.pa.us> In-Reply-To: <4338.1141581591@sss.pgh.pa.us> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 05 Mar 2006 17:22:38 -0500 Message-ID: <87d5h0pm4x.fsf@stark.xeocode.com> Lines: 27 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.129 required=5 tests=[AWL=0.129] X-Spam-Score: 0.129 X-Spam-Level: X-Archive-Number: 200603/106 X-Sequence-Number: 24452 Tom Lane writes: > A SQL-language function like this should get inlined into the query, > so that you don't lose any performance compared to writing out the > full expression each time. I think what's going on here is that he doesn't really want a function in the programming sense. A function takes arguments and returns a result based on those arguments. It would be trivial to make a function that returns true or false for his constraints but it would require passing in the columns as well as the values he's testing against. So it would be "xpath(ltreecolumn, 42, 47)". What he's looking for is a convenience macro that hides the columns he's testing against so he doesn't have to write the columns in every query. So he can just type "xpath(42,47)" without retyping "ltreecolumn". Afaik there's no functionality for this in Postgres. functions aren't given any context information when they're executed aside from the arguments passed. If I understand what you want then I think you're much better off just typing the name of the column you're testing against explicitly every time anyways. One day you'll need more flexibility or you'll have someone else reading the code and you'll be glad you're not hiding what's going on and hard coding column names inside some macro function anyways. -- greg