Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E4CC31337B2F for ; Wed, 13 Apr 2011 18:50:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 16429-09 for ; Wed, 13 Apr 2011 21:50:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 8AE1E133798E for ; Wed, 13 Apr 2011 18:50:18 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p3DLoGYr025681; Wed, 13 Apr 2011 17:50:16 -0400 (EDT) To: "Paul Deschamps" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5978: Running postgress in a shell script fails In-reply-to: <201104131815.p3DIFV3N065457@wwwmaster.postgresql.org> References: <201104131815.p3DIFV3N065457@wwwmaster.postgresql.org> Comments: In-reply-to "Paul Deschamps" message dated "Wed, 13 Apr 2011 18:15:31 +0000" Date: Wed, 13 Apr 2011 17:50:16 -0400 Message-ID: <25680.1302731416@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/86 X-Sequence-Number: 30005 "Paul Deschamps" 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