Re: proposal: multiple psql option -c - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: multiple psql option -c
Date
Msg-id CAFj8pRAoWrvp132kA0fLtGmtz9D0KTpT+hKpfncwRcjHkrHjcg@mail.gmail.com
Whole thread Raw
In response to Re: proposal: multiple psql option -c  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: proposal: multiple psql option -c  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Re: proposal: multiple psql option -c  (Adam Brightwell <adam.brightwell@crunchydatasolutions.com>)
List pgsql-hackers
Hi

2015-08-26 13:12 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:
Hi

2015-07-29 21:05 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:
Hi

here is proof concept patch

It should be cleaned, but it demonstrates a work well

[pavel@localhost psql]$ ./psql  -C 'select 10 x; select 20 y;'  -C "\l" postgres
 x 
----
 10
(1 row)

 y 
----
 20
(1 row)

                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges  
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)


2015-07-28 18:46 GMT+02:00 Andrew Dunstan <andrew@dunslane.net>:

On 07/28/2015 11:52 AM, Pavel Stehule wrote:


2015-07-28 15:16 GMT+02:00 Andrew Dunstan <andrew@dunslane.net <mailto:andrew@dunslane.net>>:


    On 07/28/2015 12:08 AM, Pavel Stehule wrote:



        2015-07-28 5:24 GMT+02:00 Pavel Stehule
        <pavel.stehule@gmail.com <mailto:pavel.stehule@gmail.com>
        <mailto:pavel.stehule@gmail.com
        <mailto:pavel.stehule@gmail.com>>>:



            2015-07-27 21:57 GMT+02:00 Andrew Dunstan
        <andrew@dunslane.net <mailto:andrew@dunslane.net>
            <mailto:andrew@dunslane.net <mailto:andrew@dunslane.net>>>:



                On 07/27/2015 02:53 PM, Pavel Stehule wrote:





                    I am trying to run parallel execution

                    psql -At -c "select datname from pg_database"
        postgres |
                    xargs -n 1 -P 3 psql -c "select current_database()"




                I don't think it's going to be a hugely important
        feature, but
                I don't see a problem with creating a new option (-C seems
                fine) which would have the same effect as if the arguments
                were contatenated into a file which is then used with
        -f. IIRC
                -c has some special characteristics which means it's
        probably
                best not to try to extend it for this feature.


            ok, I'll try to write patch.


        I have a question. Can be -C option multiple?

        The SQL is without problem, but what about \x command?

        postgres=# \dt \dn select 10;
        No relations found.
        List of schemas
        ┌──────┬───────┐
        │ Name │ Owner │
        ╞══════╪═══════╡
        └──────┴───────┘
        (0 rows)

        \dn: extra argument "10;" ignored



    I don't understand the question.

    You should include one sql or psql command per -C option, ISTM. e.g.

        psql -C '\dt' -C '\dn' -C 'select 10;'


    Isn't that what we're talking about with this whole proposal?



I am searching some agreement, how to solve a current "-c" limits. I am 100% for >>> psql -C '\dt' -C '\dn' -C 'select 10;' <<<



I think you're probably best off leaving -c alone. If there are issues to be solved for -c they should be handled separately from the feature we agree on.

cheers

andrew





here is finished patch - cleaned, tested - the significant change is using -g --group-command instead "-C"

[pavel@localhost psql]$ ./psql postgres -g "select 10; select 20" -g "select 30"
 ?column?
----------
       10
(1 row)

 ?column?
----------
       20
(1 row)

 ?column?
----------
       30
(1 row)
 
Regards


with -1 option support


 
Pavel

Attachment

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: strange test in psql:startup.c
Next
From: Stephen Frost
Date:
Subject: Re: exposing pg_controldata and pg_config as functions