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 DE79D9DCE1C for ; Sun, 5 Mar 2006 13:59:57 -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 77057-08 for ; Sun, 5 Mar 2006 13:59:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 83F6C9DCE10 for ; Sun, 5 Mar 2006 13:59:51 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k25HxpwR004339; Sun, 5 Mar 2006 12:59:52 -0500 (EST) To: sramsay@uga.edu cc: pgsql-sql@postgresql.org Subject: Re: functions in WHERE clause In-reply-to: <20060305151652.GA14216@cantor.english.uga.edu> References: <20060305151652.GA14216@cantor.english.uga.edu> Comments: In-reply-to sramsay@uga.edu message dated "Sun, 05 Mar 2006 10:16:52 -0500" Date: Sun, 05 Mar 2006 12:59:51 -0500 Message-ID: <4338.1141581591@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.112 required=5 tests=[AWL=0.112] X-Spam-Score: 0.112 X-Spam-Level: X-Archive-Number: 200603/97 X-Sequence-Number: 24443 sramsay@uga.edu writes: > 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, You mean like replacing SELECT * from some_table WHERE x = 42 AND y = 77 with create function mytest(int,int) returns bool as $$select $1 = 42 AND $2 = 77$$ language sql; SELECT * from some_table WHERE mytest(x,y); 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. regards, tom lane