Re: Adding flexibilty to queries

From: James Thompson <jamest(at)math(dot)ksu(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Adding flexibilty to queries
Date: 2004-03-25 17:30:01
Message-ID: 200403251130.01267.jamest@math.ksu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You can make it interactive if you are working from a unix box.

jamest(at)hobbes:~$ more zip.sql
\echo -n 'Zip to search for: '
\set value `read input; echo $input`
select * from zipcode where zip = :value

Not sure how/if you could do this on a windows box.

Take Care,
James

On Thursday 25 March 2004 08:45 am, you wrote:
> > > I have a question regarding psql. As I am more familiar with oracle I
> > > can write the following select and make it rather flexible:
> > > select name
> > > from name_table
> > > where person_id = &id;
> > > The &id portion is what I am looking for in PostgreSQL. Basically when
> > > running this query, the person running the query is prompted to supply
> > > a value. What is the equivalent in postgres?
>
> It doesn't work interactively, but you can assign variables like this:
>
> select name from name_table where person_id = :id;
>
> I have to admit there are some sqlplus features I miss too (like the break
> and compute features), and maybe one of these days I'll miss them enough
> to add them to psql. :-)
> --
> Mike Nolan
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

--
->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<
James Thompson 138 Cardwell Hall Manhattan, Ks 66506 785-532-0561
Kansas State University Department of Mathematics
->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2004-03-25 18:18:00 Re: PHP or JSP? That is the question.
Previous Message Uwe C. Schroeder 2004-03-25 17:28:19 Re: Memory usage during vacuum