Re: using placeholders in psql

Lists: pgsql-interfaces
From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: <pgsql-interfaces(at)postgresql(dot)org>
Cc: <peter_e(at)gmx(dot)net>
Subject: using placeholders in psql
Date: 2001-05-05 18:44:09
Message-ID: Pine.GSO.4.33.0105052140250.19681-100000@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Peter,

just an idea to use placeholders (?) in psql.
It would be useful for interactive work and debuging.
We already have powerful features in psql but sometimes
we need more. If user enter select string with placeholder,
he may get prompt to input something for arg1, then for arg2...

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
Cc: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: using placeholders in psql
Date: 2001-05-05 21:28:20
Message-ID: Pine.LNX.4.30.0105052323200.769-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Oleg Bartunov writes:

> just an idea to use placeholders (?) in psql.
> It would be useful for interactive work and debuging.
> We already have powerful features in psql but sometimes
> we need more. If user enter select string with placeholder,
> he may get prompt to input something for arg1, then for arg2...

You can simulate this:

$ cat test.sql
\echo -n 'Enter something: '
\set val1 `read && echo $REPLY`

\echo -n 'And something else: '
\set val2 `read && echo $REPLY`

select :val1, :val2;

$ psql -f test.sql
Enter something: 55<enter>
And something else: 77<enter>
?column? | ?column?
----------+----------
55 | 77
(1 row)

Does this work for your application?

The question marks pose too much of an incompatibility problem. The :var
notation was already much disputed, even though it's kind of standard.

--
Peter Eisentraut peter_e(at)gmx(dot)net http://funkturm.homeip.net/~peter


From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: using placeholders in psql
Date: 2001-05-06 09:34:59
Message-ID: Pine.GSO.4.33.0105061228221.19271-100000@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

On Sat, 5 May 2001, Peter Eisentraut wrote:

> Oleg Bartunov writes:
>
> > just an idea to use placeholders (?) in psql.
> > It would be useful for interactive work and debuging.
> > We already have powerful features in psql but sometimes
> > we need more. If user enter select string with placeholder,
> > he may get prompt to input something for arg1, then for arg2...
>
> You can simulate this:
>
> $ cat test.sql
> \echo -n 'Enter something: '
> \set val1 `read && echo $REPLY`
>
> \echo -n 'And something else: '
> \set val2 `read && echo $REPLY`
>
> select :val1, :val2;
>
> $ psql -f test.sql
> Enter something: 55<enter>
> And something else: 77<enter>
> ?column? | ?column?
> ----------+----------
> 55 | 77
> (1 row)
>
> Does this work for your application?

Thanks for the tip. Sure, it works.
But my thought was about intrinsic feature of psql.
Most time I use psql is for interactive debugging. With history
feature it would be very convenient.

>
> The question marks pose too much of an incompatibility problem. The :var
> notation was already much disputed, even though it's kind of standard.
>

question mark is just borrowed from DBI syntax, no problem with
:var

>

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83