pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Steve - DND <postgres@digitalnothing.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Junk queries with variables?
Date: Thu, 24 Feb 2005 08:23:39 +0000
Message-ID: <421D8F0B.1060409@archonet.com> (raw)
In-Reply-To: <LDEHKBBOEMIJKHKBOFNFGEEHLLAA.postgres@digitalnothing.com>
References: <LDEHKBBOEMIJKHKBOFNFGEEHLLAA.postgres@digitalnothing.com>

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



view thread (13+ messages)  latest in thread

Message-ID: <421D8F0B.1060409@archonet.com>
Permalink:  ../421D8F0B.1060409@archonet.com/
Also on:    postgresql.org/message-id/421D8F0B.1060409@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, postgres@digitalnothing.com
  Subject: Re: Junk queries with variables?
  In-Reply-To: <421D8F0B.1060409@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox