Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

SUPPORT MULTIPLE -C AND -F OPTIONS, AND ALLOW MIXING THEM

psql: Support multiple -c and -f options, and allow mixing them.
 
To support this, we must reconcile some historical anomalies in the
behavior of -c.  In particular, as a backward-incompatibility, -c no
longer implies --no-psqlrc.
 
Pavel Stehule (code) and Catalin Iacob (documentation).  Review by
Michael Paquier and myself.  Proposed behavior per Tom Lane.
This is really, really great. psql -c/-f support was always “tricky". For example – -c assumed -X (–no-psqlrc), and it support for multiple commands was “tricky".
Consider:
=$ psql -c 'select 1; select 2;'
 ?column? 
----------
        2
(1 row)
So it looks like it ran only 2nd command. In reality it ran both, but returned only last resultset.
Now, we can forget about it – since we can have multiple -c options, we can easily:
=$ psql -c 'select 1' -c 'select 2'
 ?column? 
----------
        1
(1 row)
 
 ?column? 
----------
        2
(1 row)
(though putting both selects in single -c, will still yield only result from 2nd select).
Now, with multiple -f, I can, for example:
=$ head *.sql
==> end.sql <==
SELECT 'Ending ...', now();
rollback;
 
==> start.sql <==
BEGIN;
    SELECT 'Started transaction', now();
 
==> work.sql <==
SELECT version(), now();
 
=$ psql -f start.sql -f work.sql -f end.sql 
BEGIN
      ?column?       |              now              
---------------------+-------------------------------
 Started transaction | 2015-12-14 20:09:20.075231+01
(1 row)
 
                                                   version                                                   |              now              
-------------------------------------------------------------------------------------------------------------+-------------------------------
 PostgreSQL 9.6devel on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010, 64-bit | 2015-12-14 20:09:20.075231+01
(1 row)
 
  ?column?  |              now              
------------+-------------------------------
 Ending ... | 2015-12-14 20:09:20.075231+01
(1 row)
 
ROLLBACK
All commands from all 3 files were run, in given order. Of course you can mix and match -c and -f too:
=$ psql -qtA -f start.sql -c "select 'first c'" -f work.sql -c "select 'second c'" -f end.sql 
BEGIN
Started transaction|2015-12-14 20:11:24.628256+01
first c
PostgreSQL 9.6devel on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010, 64-bit|2015-12-14 20:11:24.628256+01
second c
Ending ...|2015-12-14 20:11:24.628256+01
ROLLBACK
I, for one, welcome this change whole-heartedly, as it will spare me tricks with printf ‘….; …' | psql.
Thanks a lot

Comments

Popular posts from this blog

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

7 Steps to configure BDR replication in postgresql

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

Ora2PG - Oracle/MySQL to Postgres DB migration Version 20.0

PostgreSQL Introduction