Multiple psql -c / -f options

From: Jim Nasby <jim(at)nasby(dot)net>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Multiple psql -c / -f options
Date: 2013-10-17 23:05:24
Message-ID: 52606D34.3070506@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

IMHO the current behavior is broken:

decibel(at)decina:[17:46]~/pgsql/HEAD/i$bin/psql -c 'select 1' -c 'select 2'
?column?
----------
2
(1 row)

I would expect psql to either run both commands or throw an error.

What I'd personally prefer is that psql execute -c and -f (and arguably -v) in the order they're encountered, within the same session. I realize you can get the same behavior by creating a .sql file, but for simple needs that's sometimes more hassle than it's worth.

If we don't want to support that, we should throw an error if we encounter more than one -c|-f. Not doing so allows for subtle, silent breakage.

Related to this, there's a bunch of other options that should only be allowed once (ie: -d).

BTW, why do we special-case -? and -V at the top of main?

if (argc > 1)
{
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
usage();
exit(EXIT_SUCCESS);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{
showVersion();
exit(EXIT_SUCCESS);
}
}
--
Jim C. Nasby, Data Architect jim(at)nasby(dot)net
512.569.9461 (cell) http://jim.nasby.net

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jaime Casanova 2013-10-18 04:13:40 Re: Turning recovery.conf into GUCs
Previous Message Andres Freund 2013-10-17 22:10:17 Re: signed vs. unsigned in TYPEALIGN (was Re: space reserved for WAL record does not match what was written: panic on windows)