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 CCD339DCCE2 for ; Thu, 16 Feb 2006 11:38:30 -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 20617-03 for ; Thu, 16 Feb 2006 11:38:29 -0400 (AST) X-Greylist: delayed 00:29:59.856272 by SQLgrey- Received: from smtpout.eastlink.ca (smtpout.eastlink.ca [24.222.0.30]) by postgresql.org (Postfix) with ESMTP id 6C8569DC97D for ; Thu, 16 Feb 2006 11:38:18 -0400 (AST) Received: from ip03.eastlink.ca ([24.222.10.15]) by mta01.eastlink.ca (Sun Java System Messaging Server 6.2-4.03 (built Sep 22 2005)) with ESMTP id <0IUS008GMCOGQSW0@mta01.eastlink.ca> for pgsql-sql@postgresql.org; Thu, 16 Feb 2006 11:07:29 -0400 (AST) Received: from blk-224-208-192.eastlink.ca (HELO tickletrunk.engtech.eng) ([24.224.208.192]) by ip03.eastlink.ca with ESMTP; Thu, 16 Feb 2006 11:07:53 -0400 Date: Thu, 16 Feb 2006 11:07:50 -0400 From: Michael Burke Subject: Using calculated columns as arguments in same SELECT To: pgsql-sql@postgresql.org Message-id: <200602161107.50608.michael@engtech.ca> Organization: Engineering Technologies Canada Ltd. MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline X-BrightmailFiltered: true X-Brightmail-Tracker: AAAAAQAAA+k= User-Agent: KMail/1.8.3 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200602/206 X-Sequence-Number: 24216 Hello, I am looking to simplify this query (uses PostGIS, but I have encountered this scenario with other chains of functions): gtest=# SELECT X( SetSRID( Transform( GeomFromText( 'POINT(142512 1020225)', 26910 ), 4326 ), -1) ) as xcoord, Y( SetSRID( Transform( GeomFromText( 'POINT(142512 1020225)', 26910 ), 4326 ), -1) ) AS ycoord; This SELECT works, but the rather long arguments to X(geom) and Y(geom) are the same. Is it possible and feasible to pre-calculate the argument, such as: gtest=# SELECT SetSRID( Transform( GeomFromText( 'POINT(142512 1020225)', 26910 ), 4326 ), -1) AS transformed_geom, X(transformed_geom) AS xcoord, Y(transformed_geom) AS ycoord Where I don't really care about transformed_geom being returned, but it saves double-calling the inside functions This doesn't work -- it complains that transformed_geom is not a column. SELECT version(); gives: PostgreSQL 8.0.6 on i386-portbld-freebsd5.4, compiled by GCC cc (GCC) 3.4.2 [FreeBSD] 20040728 Thanks in advance! Mike. -- Michael Burke Engineering Technologies Canada Ltd. michael@engtech.ca 1 (902) 628-1705