pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedUser input to queries
14+ messages / 5 participants
[nested] [flat]
* User input to queries
@ 2020-12-09 17:03 Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:29 ` Re: User input to queries Rob Sargent <robjsargent@gmail.com>
2020-12-09 17:35 ` Re: User input to queries Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 3 replies; 14+ messages in thread
From: Rich Shepard @ 2020-12-09 17:03 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
While I develop the application's GUI I use the database from the command
line (psql). While some queries are self-contained others need user input.
I've not found a search term that locates this information in the
postgres-12 user manual and my web searches suggest that using '&' should
work.
I tried the latter with this query but postgres didn't like it. (There may
well be other errors in it so don't hesitate to point out my mistakes.)
------
/* This query selects all activity information for a named person */
/* Specify columns */
SELECT p.lname, p.fname, p.loc_nbr, p.job_title, p.direct_phone, p.active,
o.org_name,
l.loc_nbr, l.loc_name,
a.act_date, a.act_type, a.notes, a.next_contact
/* Specify tables. */
FROM People AS p
JOIN Organizations AS o ON o.org_nbr = p.org_nbr
JOIN Locations AS l ON l.org_nbr = o.org_nbr and l.loc_nbr = p.loc_nbr
JOIN Activities AS a ON a.person_nbr = p.person_nbr
/* Specify rows */
WHERE p.lname = &p.lname AND p.fname = &p.fname;
-----
Suggestions on what I should read to learn more about this subject are
appreciated.
Regards,
Rich
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 17:09 ` Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2 siblings, 1 reply; 14+ messages in thread
From: Michael Lewis @ 2020-12-09 17:09 UTC (permalink / raw)
To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
On Wed, Dec 9, 2020 at 10:04 AM Rich Shepard <rshepard@appl-ecosys.com>
wrote:
> While I develop the application's GUI I use the database from the command
> line (psql). While some queries are self-contained others need user input.
> I've not found a search term that locates this information in the
> postgres-12 user manual and my web searches suggest that using '&' should
> work.
>
> I tried the latter with this query but postgres didn't like it. (There may
> well be other errors in it so don't hesitate to point out my mistakes.)
>
> ------
> /* This query selects all activity information for a named person */
>
> /* Specify columns */
> SELECT p.lname, p.fname, p.loc_nbr, p.job_title, p.direct_phone, p.active,
> o.org_name,
> l.loc_nbr, l.loc_name,
> a.act_date, a.act_type, a.notes, a.next_contact
> /* Specify tables. */
> FROM People AS p
> JOIN Organizations AS o ON o.org_nbr = p.org_nbr
> JOIN Locations AS l ON l.org_nbr = o.org_nbr and l.loc_nbr =
> p.loc_nbr
> JOIN Activities AS a ON a.person_nbr = p.person_nbr
> /* Specify rows */
> WHERE p.lname = &p.lname AND p.fname = &p.fname;
> -----
>
> Suggestions on what I should read to learn more about this subject are
> appreciated.
>
> Regards,
>
> Rich
Are you looking for this perhaps?
https://www.postgresql.org/docs/current/sql-prepare.html
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
@ 2020-12-09 17:24 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
0 siblings, 1 reply; 14+ messages in thread
From: Rich Shepard @ 2020-12-09 17:24 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
On Wed, 9 Dec 2020, Michael Lewis wrote:
> Are you looking for this perhaps?
> https://www.postgresql.org/docs/current/sql-prepare.html
Michael,
I don't think so. Reading the PREPARE doc page my understanding is that its
use is for statement execution optimization, not asking for user data input
for variables in the query statement. It's useful information, though not
for my immediate need.
Thanks and stay well,
Rich
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 17:27 ` Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
0 siblings, 1 reply; 14+ messages in thread
From: Michael Lewis @ 2020-12-09 17:27 UTC (permalink / raw)
To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
What application is taking the user input and needs to include the
parameters in the query string?
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
@ 2020-12-09 17:53 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:58 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Rich Shepard @ 2020-12-09 17:53 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
On Wed, 9 Dec 2020, Michael Lewis wrote:
> What application is taking the user input and needs to include the
> parameters in the query string?
Michael,
My business tracking tool. Yes, the GUI will have text entry widgets for
user input but I want to apply these queries using psql on the command line
until I build the GUI.
Rich
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 17:58 ` Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:10 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
0 siblings, 1 reply; 14+ messages in thread
From: Paul Förster @ 2020-12-09 17:58 UTC (permalink / raw)
To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Hi Rich,
> On 09. Dec, 2020, at 18:53, Rich Shepard <rshepard@appl-ecosys.com> wrote:
>
> My business tracking tool. Yes, the GUI will have text entry widgets for
> user input but I want to apply these queries using psql on the command line
> until I build the GUI.
maybe you're looking for this?
https://stackoverflow.com/a/7389606
Cheers,
Paul
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:58 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
@ 2020-12-09 18:10 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 18:14 ` Re: User input to queries Rob Sargent <robjsargent@gmail.com>
2020-12-09 18:17 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
0 siblings, 2 replies; 14+ messages in thread
From: Rich Shepard @ 2020-12-09 18:10 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
On Wed, 9 Dec 2020, Paul Förster wrote:
> maybe you're looking for this?
> https://stackoverflow.com/a/7389606
Paul,
That looks very useful and I'll try the provided answers.
Looking at the postgres-12 doc I cannot find a command 'PROMPT' anywhere in
it.
Thanks,
Rich
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:58 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:10 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 18:14 ` Rob Sargent <robjsargent@gmail.com>
1 sibling, 0 replies; 14+ messages in thread
From: Rob Sargent @ 2020-12-09 18:14 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 12/9/20 11:10 AM, Rich Shepard wrote:
> On Wed, 9 Dec 2020, Paul Förster wrote:
>
>> maybe you're looking for this?
>> https://stackoverflow.com/a/7389606
>
> Paul,
>
> That looks very useful and I'll try the provided answers.
>
> Looking at the postgres-12 doc I cannot find a command 'PROMPT'
> anywhere in
> it.
>
> Thanks,
>
> Rich
>
>
https://www.postgresql.org/docs/12/app-psql.html
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:58 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:10 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 18:17 ` Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:22 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
1 sibling, 1 reply; 14+ messages in thread
From: Paul Förster @ 2020-12-09 18:17 UTC (permalink / raw)
To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Hi Rich,
> On 09. Dec, 2020, at 19:10, Rich Shepard <rshepard@appl-ecosys.com> wrote:
>
> Looking at the postgres-12 doc I cannot find a command 'PROMPT' anywhere in
> it.
but 12 has it:
postgres=# \prompt 'input: ' input
input: this is test input
postgres=# select version(), :'input';
version | ?column?
------------------------------------------------------------------------------------+--------------------
PostgreSQL 12.5 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux) 7.5.0, 64-bit | this is test input
(1 row)
postgres=# \?
...
Variables
\prompt [TEXT] NAME prompt user to set internal variable
\set [NAME [VALUE]] set internal variable, or list all if no parameters
\unset NAME unset (delete) internal variable
...
Cheers,
Paul
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:58 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:10 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 18:17 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
@ 2020-12-09 18:22 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 18:25 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Rich Shepard @ 2020-12-09 18:22 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
On Wed, 9 Dec 2020, Paul Förster wrote:
> but 12 has it:
>
> postgres=# \prompt 'input: ' input
> input: this is test input
> postgres=# select version(), :'input';
Paul,
Okay. I use mupdf to view the document and my search string were 'prompt',
and 'prompt command'. I didn't use '\prompt',
Thanks again,
Rich
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Re: User input to queries Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:58 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:10 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 18:17 ` Re: User input to queries Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:22 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 18:25 ` Paul Förster <paul.foerster@gmail.com>
0 siblings, 0 replies; 14+ messages in thread
From: Paul Förster @ 2020-12-09 18:25 UTC (permalink / raw)
To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Hi Rich,
> On 09. Dec, 2020, at 19:22, Rich Shepard <rshepard@appl-ecosys.com> wrote:
>
> Okay. I use mupdf to view the document and my search string were 'prompt',
> and 'prompt command'. I didn't use '\prompt',
\prompt is a psql special command, hence the backslash. Only psql knows that, the database does not, as with all backslash commands.
Cheers,
Paul
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 17:29 ` Rob Sargent <robjsargent@gmail.com>
2020-12-09 17:56 ` Re: User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2 siblings, 1 reply; 14+ messages in thread
From: Rob Sargent @ 2020-12-09 17:29 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 12/9/20 10:03 AM, Rich Shepard wrote:
> While I develop the application's GUI I use the database from the command
> line (psql). While some queries are self-contained others need user
> input.
> I've not found a search term that locates this information in the
> postgres-12 user manual and my web searches suggest that using '&' should
> work.
>
> I tried the latter with this query but postgres didn't like it. (There
> may
> well be other errors in it so don't hesitate to point out my mistakes.)
>
> ------
> /* This query selects all activity information for a named person */
>
> /* Specify columns */
> SELECT p.lname, p.fname, p.loc_nbr, p.job_title, p.direct_phone,
> p.active,
> o.org_name,
> l.loc_nbr, l.loc_name,
> a.act_date, a.act_type, a.notes, a.next_contact
> /* Specify tables. */ FROM People AS p
> JOIN Organizations AS o ON o.org_nbr = p.org_nbr
> JOIN Locations AS l ON l.org_nbr = o.org_nbr and l.loc_nbr =
> p.loc_nbr
> JOIN Activities AS a ON a.person_nbr = p.person_nbr
> /* Specify rows */ WHERE p.lname = &p.lname AND p.fname = &p.fname;
> -----
>
> Suggestions on what I should read to learn more about this subject are
> appreciated.
>
> Regards,
>
> Rich
>
>
Put the query in a file, set the desired name, then from psql
\i filename
Edit pfname, repeat
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:29 ` Re: User input to queries Rob Sargent <robjsargent@gmail.com>
@ 2020-12-09 17:56 ` Rich Shepard <rshepard@appl-ecosys.com>
0 siblings, 0 replies; 14+ messages in thread
From: Rich Shepard @ 2020-12-09 17:56 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On Wed, 9 Dec 2020, Rob Sargent wrote:
> Put the query in a file, set the desired name, then from psql
> \i filename
> Edit pfname, repeat
Thanks, Rob.
Stay well,
Rich
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: User input to queries
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
@ 2020-12-09 17:35 ` Laurenz Albe <laurenz.albe@cybertec.at>
2 siblings, 0 replies; 14+ messages in thread
From: Laurenz Albe @ 2020-12-09 17:35 UTC (permalink / raw)
To: Rich Shepard <rshepard@appl-ecosys.com>; pgsql-general@lists.postgresql.org
On Wed, 2020-12-09 at 09:03 -0800, Rich Shepard wrote:
> While I develop the application's GUI I use the database from the command
> line (psql). While some queries are self-contained others need user input.
> I've not found a search term that locates this information in the
> postgres-12 user manual and my web searches suggest that using '&' should
> work.
>
> I tried the latter with this query but postgres didn't like it. (There may
> well be other errors in it so don't hesitate to point out my mistakes.)
>
> ------
> /* This query selects all activity information for a named person */
>
> /* Specify columns */
> SELECT p.lname, p.fname, p.loc_nbr, p.job_title, p.direct_phone, p.active,
> o.org_name,
> l.loc_nbr, l.loc_name,
> a.act_date, a.act_type, a.notes, a.next_contact
> /* Specify tables. */
> FROM People AS p
> JOIN Organizations AS o ON o.org_nbr = p.org_nbr
> JOIN Locations AS l ON l.org_nbr = o.org_nbr and l.loc_nbr = p.loc_nbr
> JOIN Activities AS a ON a.person_nbr = p.person_nbr
> /* Specify rows */
> WHERE p.lname = &p.lname AND p.fname = &p.fname;
> -----
>
> Suggestions on what I should read to learn more about this subject are
> appreciated.
You probably need the \prompt psql command:
\prompt 'What is "p.lname"' p_lname
\prompt 'What is "p.fname"' p_fname
SELECT ... WHERE p.lname = :p_lname AND p.fname = :p_fname;
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 14+ messages in thread
end of thread, other threads:[~2020-12-09 18:25 UTC | newest]
Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 17:03 User input to queries Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:09 ` Michael Lewis <mlewis@entrata.com>
2020-12-09 17:24 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:27 ` Michael Lewis <mlewis@entrata.com>
2020-12-09 17:53 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:58 ` Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:10 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 18:14 ` Rob Sargent <robjsargent@gmail.com>
2020-12-09 18:17 ` Paul Förster <paul.foerster@gmail.com>
2020-12-09 18:22 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 18:25 ` Paul Förster <paul.foerster@gmail.com>
2020-12-09 17:29 ` Rob Sargent <robjsargent@gmail.com>
2020-12-09 17:56 ` Rich Shepard <rshepard@appl-ecosys.com>
2020-12-09 17:35 ` Laurenz Albe <laurenz.albe@cybertec.at>
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