X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8C3F45641B for ; Thu, 24 Feb 2005 08:23:44 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36363-01 for ; Thu, 24 Feb 2005 08:23:35 +0000 (GMT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id 99725563EE for ; Thu, 24 Feb 2005 08:23:34 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 4.42) id 1D4EFl-000GQj-GO; Thu, 24 Feb 2005 08:21:45 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id E547E15D10; Thu, 24 Feb 2005 08:23:39 +0000 (GMT) Message-ID: <421D8F0B.1060409@archonet.com> Date: Thu, 24 Feb 2005 08:23:39 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Steve - DND Cc: pgsql-sql@postgresql.org Subject: Re: Junk queries with variables? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.063 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200502/296 X-Sequence-Number: 20406 Steve - DND wrote: > I really have to be missing something here and this probably a *really* noob > question. I don't have a problem running little junk queries in the pgAdmin > query window(SELECT blah FROM blah, INSERT INTO blah, etc...), but I can't > figure out how to run queries with variables outside of a function. I just > want to use variables without having to go about creating and dropping a > function for every stupid little query I need to write. Example: > > amount int4 := 1000; > earliest_date timestamp := current_timestamp; Michael's given you one option - another to look at is PREPARE/EXECUTE PREPARE my_query(int4) AS INSERT INTO foo VALUES ($1); EXECUTE my_query(1); EXECUTE my_query(7); ... -- Richard Huxton Archonet Ltd