Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 2AEEF9FB24E for ; Wed, 7 Feb 2007 21:56:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 76570-03 for ; Wed, 7 Feb 2007 21:56:15 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.188]) by postgresql.org (Postfix) with ESMTP id A65FB9FB1F2 for ; Wed, 7 Feb 2007 21:56:14 -0400 (AST) Received: by nf-out-0910.google.com with SMTP id x4so700796nfb for ; Wed, 07 Feb 2007 17:56:13 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=H0vlN0ffQe5MKuObOm8gmE35pQ20lmhTCCrxjRERcBchh/2uJTh9Oeg/4JtXZa5wdZjeD1JsY3hQidNLfgb7dp2GZntVl6gXJ8qDitmwcS1YxJPPVqD+hozMLc+JIoQOE0/FHv6UKacZ7IYQqIj3xdX094xeErXO/1zIoTp7Zw8= Received: by 10.82.135.13 with SMTP id i13mr600225bud.1170899772520; Wed, 07 Feb 2007 17:56:12 -0800 (PST) Received: by 10.48.210.4 with HTTP; Wed, 7 Feb 2007 17:56:12 -0800 (PST) Message-ID: <81961ff50702071756j62247349k7062839ec44901a5@mail.gmail.com> Date: Wed, 7 Feb 2007 20:56:12 -0500 From: "Chad Wagner" To: "Karthikeyan Sundaram" Subject: Re: [SQL] question on passing parameter in sql query Cc: pgsql-admin@postgresql.org, pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_23371_9455834.1170899772460" References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/117 X-Sequence-Number: 24582 ------=_Part_23371_9455834.1170899772460 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 2/7/07, Karthikeyan Sundaram 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/ ------=_Part_23371_9455834.1170899772460 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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/
------=_Part_23371_9455834.1170899772460--