From: Tom Lane <tgl@sss.pgh.pa.us>
To: Paul Deschamps <pdescham49@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5978: Running postgress in a shell script fails
Date: Wed, 13 Apr 2011 17:50:16 -0400
Message-ID: <25680.1302731416@sss.pgh.pa.us> (raw)
In-Reply-To: <201104131815.p3DIFV3N065457@wwwmaster.postgresql.org>
References: <201104131815.p3DIFV3N065457@wwwmaster.postgresql.org>
"Paul Deschamps" <pdescham49@gmail.com> writes:
> PostgreSQL version: 8.4.6
> Operating system: Ubuntu 10.4
> Description: Running postgress in a shell script fails
> Details:
> When running postgres in a shell using the -c option it looks as though it
> parses the contents of the --command as command line arguments.
> Running Command:psql postgres -c"SELECT tablename FROM PG_TABLES limit 1;"
> TEST 1
> psql: warning: extra command-line argument "FROM" ignored
> psql: warning: extra command-line argument "PG_TABLES" ignored
> psql: warning: extra command-line argument "limit" ignored
> psql: warning: extra command-line argument "1;"" ignored
> psql: FATAL: role "tablename" does not exist
I think this is a bug in Ubuntu's version of getopt_long(); it does not
happen that way for me on any of the platforms I use. I get either
psql: FATAL: role "-cSELECT tablename FROM PG_TABLES limit 1;" does not exist
on platforms where getopt_long does not think it has a charter to try to
rearrange command line arguments, or
$ psql postgres -c"SELECT tablename FROM PG_TABLES limit 1;"
tablename
--------------
pg_statistic
(1 row)
on platforms where getopt_long does move the database name after the
switch+argument. What you've evidently got is a getopt_long that tries
to rearrange the command-line arguments but produces the equivalent of
psql "-cSELECT" "postgres" "tablename" "FROM" "PG_TABLES" "limit" "1;"
which is flat out wrong.
Recommendation is to use the documented command line order, which is
psql [OPTION]... [DBNAME [USERNAME]]
rather than assuming getopt_long will fix it for you.
You can try filing a bug against Ubuntu's glibc, but I dunno whether
you'll get any satisfaction there. I think we've heard of this before
and the misbehavior is of long standing.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, pdescham49@gmail.com
Subject: Re: BUG #5978: Running postgress in a shell script fails
In-Reply-To: <25680.1302731416@sss.pgh.pa.us>
References: <201104131815.p3DIFV3N065457@wwwmaster.postgresql.org> <25680.1302731416@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox