pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chad Wagner <chad.wagner@gmail.com>
To: Karthikeyan Sundaram <skarthi98@hotmail.com>
Cc: pgsql-admin@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] question on passing parameter in sql query
Date: Wed, 7 Feb 2007 20:56:12 -0500
Message-ID: <81961ff50702071756j62247349k7062839ec44901a5@mail.gmail.com> (raw)
In-Reply-To: <BAY131-F28E2CC1D1B622B218CD5C3B09D0@phx.gbl>
References: <BAY131-F28E2CC1D1B622B218CD5C3B09D0@phx.gbl>

On 2/7/07, Karthikeyan Sundaram <skarthi98@hotmail.com> wrote:
>
>    I don't want to compare with Oracle and postgres. But I have a
> situation.
>   I am using psql command line tool supplied by postgres.
>
>    In Oracle I can say
>
>     select * from emp where emp_id = &1
>
>    Oracle will ask:
>    Enter a value for 1:
>
>    If I enter 10, then Oracle will get the empid=10
>
>   What is the equal command in postgres ?
>

It can be done, but it is a bit "different" and this method is UNIX
dependent:

test=# create table data (x integer not null primary key);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "data_pkey"
for table "data"
CREATE TABLE
test=# insert into data values (1),(2),(3),(4);
INSERT 0 4
test=# \set foo `head -1`
3
test=# \echo :foo
3
test=# select * from data where x = :foo;
 x
---
 3
(1 row)


I don't believe it automatically prompts the way Oracle does.  It would be
nice if there was a built-in "\prompt [VARIABLE] [TEXT]".


--
Chad
http://www.postgresqlforums.com/

view thread (2+ messages)

Message-ID: <81961ff50702071756j62247349k7062839ec44901a5@mail.gmail.com>
Permalink:  ../81961ff50702071756j62247349k7062839ec44901a5@mail.gmail.com/
Also on:    postgresql.org/message-id/81961ff50702071756j62247349k7062839ec44901a5@mail.gmail.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: chad.wagner@gmail.com, skarthi98@hotmail.com, pgsql-admin@postgresql.org
  Subject: Re: [SQL] question on passing parameter in sql query
  In-Reply-To: <81961ff50702071756j62247349k7062839ec44901a5@mail.gmail.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