Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id B488E9FB51E for ; Tue, 3 Apr 2007 10:53:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 78670-02 for ; Tue, 3 Apr 2007 10:52:49 -0300 (ADT) X-Greylist: delayed 00:27:24.95936 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 50F039FB8E0 for ; Tue, 3 Apr 2007 10:52:54 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from www.herakles.homelinux.org (coco2.arach.net.au [203.34.16.107]) by svr4.postgresql.org (Postfix) with ESMTP id 3A6CF5AF894 for ; Tue, 3 Apr 2007 13:25:29 +0000 (GMT) Received: from mail.herakles.homelinux.org (unknown [192.168.7.254]) by www.herakles.homelinux.org (Postfix) with ESMTP id 853BE5F4171 for ; Tue, 3 Apr 2007 21:25:17 +0800 (WST) Received: from mail2.cds.merseine.nu (unknown [192.168.9.4]) by mail.herakles.homelinux.org (Postfix) with ESMTP id 5F0731EA1B for ; Tue, 3 Apr 2007 21:25:19 +0800 (WST) Received: from [192.168.9.146] (Bilby.demo.lan [192.168.9.146]) by mail2.cds.merseine.nu (Postfix) with ESMTP id 755D0CAC001 for ; Tue, 3 Apr 2007 21:25:17 +0800 (WST) Message-ID: <461254DF.5090500@herakles.homelinux.org> Date: Tue, 03 Apr 2007 21:21:35 +0800 From: John Summerfield User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20061007 SeaMonkey/1.0.5 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Using a variable as a view name in a select References: <7CCC5BEF5E72394C963E529B54EB4A642A19B3@SD01ITMV12.PROD.NET> In-Reply-To: <7CCC5BEF5E72394C963E529B54EB4A642A19B3@SD01ITMV12.PROD.NET> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200704/29 X-Sequence-Number: 28029 Wilkinson, Jim wrote: > I have created a view, called april_may. I need to select this view by > combineing to fields in the database to create the view name etc ... Jim Learn to use "compose" or "write" and not "reply" when you want to ask a fresh question. My email rolled this into the "LOCK" thread making it incredibly difficult to find. > > > > Create view as select * from table_X; > > > > I need to do something like this ... > > > > Select * from (select table.start_month||_||table.end_month); > > ================== > > Start_month = april > > End_month = May > > > > What I what to pass to the select is the combination of the 2 fields as > the view name. > > > > Any ideas ? The simple ways I can think of are external to postgresql, and depend on your host environment. For example, on Linux (or OS X) I might do something like this: psql -c "select * from (select table.$(date +%B -d 'last month')_table.$(date +%B))" Note, the above para is really a single line, there is a space between "last" and "month." on DOS it might be a little trickier, but probably VB Script can do it. In Java, it is somewhat similar but different. If this doesn't answer, give better info and maybe someone else can help you properly.