Re: misc psql questions

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: James Thompson <jamest(at)math(dot)ksu(dot)edu>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: misc psql questions
Date: 2001-02-15 18:32:03
Message-ID: Pine.LNX.4.30.0102151928270.1211-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

James Thompson writes:

> About a lifetime ago I used to do quite a bit of work w/ Oracle.
>
> It's command line sql tool had some pretty nice features that I haven't
> been able to find in psql. I was wondering if any of the following
> existed....
>
> I think the first was called break on which altered in output from
> something like
>
> name date qty
> -------------------------
> Fred 01-JAN-2000 10
> Fred 10-JAN-2000 13
> Fred 01-JUL-2000 1
> Fred 01-DEC-2000 100
> Bob 01-JAN-2000 5
> Bob 10-MAY-2000 10
>
> to
>
> name date qty
> -------------------------
> Fred 01-JAN-2000 10
> 10-JAN-2000 13
> 01-JUL-2000 1
> 01-DEC-2000 100
> Bob 01-JAN-2000 5
> 10-MAY-2000 10
>
> it also allowed for things like compute sum which would activate on breaks
> but I don't recall how they worked.

This seems to be a thing for a report generator. Try pgaccess.

> The other thing I'd love to be able to do is get user input while running
> a sql file. I don't recall how this worked exactly but the script would
> either accept variables calling the script or prompt for them.
>
> So if I had a sql script in a file named contact_report. And I did
>
> prod=> \i contact_report 01-JAN-2000 31-DEC-2001
>
> then it would load the script and replace IIRC &1 and &2 with the
> respective dates listed on command line.

You can use \set to set variables.

> It also had an ACCEPT command that would cause it to prompt for input from
> user and assign to a varable name.

Try
\echo -n 'Prompt: '
\set varname `read input; echo $input`

--
Peter Eisentraut peter_e(at)gmx(dot)net http://yi.org/peter-e/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2001-02-15 18:36:00 Re: Current Year
Previous Message Angelo DiSanto 2001-02-15 18:16:50 Question