public inbox for [email protected]  
help / color / mirror / Atom feed
Re: Using psql's \prompt command
9+ messages / 3 participants
[nested] [flat]

* Re: Using psql's \prompt command
@ 2025-01-30 21:50 David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  0 siblings, 1 reply; 9+ messages in thread

From: David G. Johnston @ 2025-01-30 21:50 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; +Cc: pgsql-general

On Thursday, January 30, 2025, Rich Shepard <[email protected]>
wrote:
>
>
> What's the correct syntax for the \prompt?
>

Prompt isn’t your issue.  Prompt stores the value into a variable.  Read
how to reference variables in a psql script.

David J.


^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
@ 2025-01-30 22:28 ` Rich Shepard <[email protected]>
  2025-01-30 22:38   ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:40   ` Re: Using psql's \prompt command Ron Johnson <[email protected]>
  0 siblings, 2 replies; 9+ messages in thread

From: Rich Shepard @ 2025-01-30 22:28 UTC (permalink / raw)
  To: pgsql-general

On Thu, 30 Jan 2025, David G. Johnston wrote:

> Prompt isn’t your issue. Prompt stores the value into a variable. Read how
> to reference variables in a psql script.

David,

Thank you. I'll look into using the \set command.

Rich






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
@ 2025-01-30 22:38   ` Rich Shepard <[email protected]>
  2025-01-30 22:44     ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
  1 sibling, 1 reply; 9+ messages in thread

From: Rich Shepard @ 2025-01-30 22:38 UTC (permalink / raw)
  To: pgsql-general

On Thu, 30 Jan 2025, Rich Shepard wrote:

> Thank you. I'll look into using the \set command.

My web searches find many examples of using the \set command, but none
getting user input with \prompt.

Please point me to a reference where I can learn how to get the user input
string into the script.

Regards,

Rich






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:38   ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
@ 2025-01-30 22:44     ` David G. Johnston <[email protected]>
  2025-01-30 22:46       ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
  0 siblings, 1 reply; 9+ messages in thread

From: David G. Johnston @ 2025-01-30 22:44 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; +Cc: pgsql-general

On Thu, Jan 30, 2025 at 3:38 PM Rich Shepard <[email protected]>
wrote:

> On Thu, 30 Jan 2025, Rich Shepard wrote:
>
> > Thank you. I'll look into using the \set command.
>
> My web searches find many examples of using the \set command, but none
> getting user input with \prompt.
>
> Please point me to a reference where I can learn how to get the user input
> string into the script.
>

That is what \prompt is for.  You have the correct meta-command, you were
capturing user input just fine.  Read about how to use variables in queries
for the part you are missing.

David J.


^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:38   ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:44     ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
@ 2025-01-30 22:46       ` David G. Johnston <[email protected]>
  2025-01-30 22:47         ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 23:00         ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  0 siblings, 2 replies; 9+ messages in thread

From: David G. Johnston @ 2025-01-30 22:46 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; +Cc: pgsql-general

On Thu, Jan 30, 2025 at 3:44 PM David G. Johnston <
[email protected]> wrote:

> On Thu, Jan 30, 2025 at 3:38 PM Rich Shepard <[email protected]>
> wrote:
>
>> On Thu, 30 Jan 2025, Rich Shepard wrote:
>>
>> > Thank you. I'll look into using the \set command.
>>
>> My web searches find many examples of using the \set command, but none
>> getting user input with \prompt.
>>
>> Please point me to a reference where I can learn how to get the user input
>> string into the script.
>>
>
> That is what \prompt is for.  You have the correct meta-command, you were
> capturing user input just fine.  Read about how to use variables in queries
> for the part you are missing.
>

Specifically the section of the psql docs titled:

SQL Interpolation

David J.


^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:38   ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:44     ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:46       ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
@ 2025-01-30 22:47         ` David G. Johnston <[email protected]>
  1 sibling, 0 replies; 9+ messages in thread

From: David G. Johnston @ 2025-01-30 22:47 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; +Cc: pgsql-general

On Thu, Jan 30, 2025 at 3:46 PM David G. Johnston <
[email protected]> wrote:

> On Thu, Jan 30, 2025 at 3:44 PM David G. Johnston <
> [email protected]> wrote:
>
>> On Thu, Jan 30, 2025 at 3:38 PM Rich Shepard <[email protected]>
>> wrote:
>>
>>> On Thu, 30 Jan 2025, Rich Shepard wrote:
>>>
>>> > Thank you. I'll look into using the \set command.
>>>
>>> My web searches find many examples of using the \set command, but none
>>> getting user input with \prompt.
>>>
>>> Please point me to a reference where I can learn how to get the user
>>> input
>>> string into the script.
>>>
>>
>> That is what \prompt is for.  You have the correct meta-command, you were
>> capturing user input just fine.  Read about how to use variables in queries
>> for the part you are missing.
>>
>
> Specifically the section of the psql docs titled:
>
> SQL Interpolation
>
>
Or:

Advanced Features
- Variables

David J.


^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:38   ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:44     ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:46       ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
@ 2025-01-30 23:00         ` Rich Shepard <[email protected]>
  2025-01-30 23:35           ` Re: Using psql's \prompt command [RESOLVED] Rich Shepard <[email protected]>
  1 sibling, 1 reply; 9+ messages in thread

From: Rich Shepard @ 2025-01-30 23:00 UTC (permalink / raw)
  To: pgsql-general

On Thu, 30 Jan 2025, David G. Johnston wrote:

>> That is what \prompt is for. You have the correct meta-command, you were
>> capturing user input just fine. Read about how to use variables in
>> queries for the part you are missing.
>>
>
> Specifically the section of the psql docs titled:
>
> SQL Interpolation

Thanks again, David. I didn't know that's the section I need.

Much appreciated,

Rich






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command [RESOLVED]
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:38   ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
  2025-01-30 22:44     ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:46       ` Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 23:00         ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
@ 2025-01-30 23:35           ` Rich Shepard <[email protected]>
  0 siblings, 0 replies; 9+ messages in thread

From: Rich Shepard @ 2025-01-30 23:35 UTC (permalink / raw)
  To: pgsql-general

On Thu, 30 Jan 2025, Rich Shepard wrote:

> Thanks again, David. I didn't know that's the section I need.

David/Ron, et al.:
Got it (example on page 2126 of the doc):
-- Display person_nbr, lname, fname, direct_phone, email from people, contact history from contacts.

-- prompt for person_nbr before selecting rows:
\prompt 'Enter person_nbr: ' who

select p.person_nbr, p.lname, p.fname, p.direct_phone, p.email, c.contact_date, c.contact_time, c.contact_type, c.notes
from people as p natural inner join contacts as c
where p.person_nbr = (:'who')
order by c.contact_date, c.contact_time;

This works.

Thank you,

Rich






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Using psql's \prompt command
  2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
  2025-01-30 22:28 ` Re: Using psql's \prompt command Rich Shepard <[email protected]>
@ 2025-01-30 22:40   ` Ron Johnson <[email protected]>
  1 sibling, 0 replies; 9+ messages in thread

From: Ron Johnson @ 2025-01-30 22:40 UTC (permalink / raw)
  To: pgsql-general

On Thu, Jan 30, 2025 at 5:28 PM Rich Shepard <[email protected]>
wrote:

> On Thu, 30 Jan 2025, David G. Johnston wrote:
>
> > Prompt isn’t your issue. Prompt stores the value into a variable. Read
> how
> > to reference variables in a psql script.
>
> David,
>
> Thank you. I'll look into using the \set command.
>

Instead of \set (which can be tricky and unintuitive), consider the dialog
command with "psql --set=NAME=VALUE".

https://linux.die.net/man/1/dialog

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!


^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2025-01-30 23:35 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-01-30 21:50 Re: Using psql's \prompt command David G. Johnston <[email protected]>
2025-01-30 22:28 ` Rich Shepard <[email protected]>
2025-01-30 22:38   ` Rich Shepard <[email protected]>
2025-01-30 22:44     ` David G. Johnston <[email protected]>
2025-01-30 22:46       ` David G. Johnston <[email protected]>
2025-01-30 22:47         ` David G. Johnston <[email protected]>
2025-01-30 23:00         ` Rich Shepard <[email protected]>
2025-01-30 23:35           ` Re: Using psql's \prompt command [RESOLVED] Rich Shepard <[email protected]>
2025-01-30 22:40   ` Ron Johnson <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox