Re: Enhancement to psql command, feedback.

Поиск
Список
Период
Сортировка
От Christopher Browne
Тема Re: Enhancement to psql command, feedback.
Дата
Msg-id CAFNqd5WwBEZ5yVtzL3RPS02aUcEZF5j0+qVz82debqsjYw_HCQ@mail.gmail.com
обсуждение исходный текст
Ответ на Enhancement to psql command, feedback.  (John McKown <john.archie.mckown@gmail.com>)
Ответы Re: Enhancement to psql command, feedback.  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
On Wed, 9 May 2018 at 04:00, John McKown <john.archie.mckown@gmail.com>
wrote:
> To me this looks similar to a UNIX shell script. Now, going sideways for
a second, if someone wanted to create a "self contained" awk script. It
would look something like:

> #!/bin/awk -f
> ... awk code ...

I have found it convenient when Lisp implementations (that use ; as the
comment indicator, and where # tends to mean something quite different)
have provided something like this.

I'd quite like it if I could start a script with
#!psql
or similar and have it be, yes, indeed, directly executable via psql.

There are several complications that leap out at me...

1.  Would want to run the apropos psql

It's a common thing in Perl to have an idiom where a suitable script prefix
goes off and finds the appropriate Perl instance.  It's possible to have
multiple versions of psql, it would be kinda nice if the script could
choose the right one to run.  But that could easily be trying too hard.

2.  Specifying database connection parameters

Making use of PGDATABASE and other environment parameters is well and good;
it would also be a fine thing for something in the first line to be able to
specify values.

Thus, something like...

#!psql -d postgresql://postgres@localhost:5432/some_db_name

The not-so-nice is that perhaps that first line provides some defaults, and
one could override slices of that via PGDATABASE/PGHOST/PGUSER/...

What overrides what is an excellent question, and perhaps a horrible
bikeshedding debate.

3.  Nesting is a funny thing; I'm not sure if \i should simply ignore the
first line if it begins with #!, or if it should become a "subshell"
perhaps in another psql session.

In effect, is \i like a C #include (ergo, perhaps strip leading line
beginning with #!), or is it a separate psql session, with separate
connection/transaction?  I imagine it's more like #include, but
both seem potentially useful.

There's certainly a danger of bikeshedding.
-- 
When confronted by a difficult problem, solve it by reducing it to the
question, "How would the Lone Ranger handle this?"


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Enhancement to psql command, feedback.
Следующее
От: Bruce Harold
Дата:
Сообщение: RE: Error creating plpython3u extension