Thread: -c argument not recognized

-c argument not recognized

From
Antonio Ruggiero
Date:
I am running PostgresSQL 8.3.8 on windows XP-64Bit.  I am using psql
client from the PostgreSQL installation and not the Cygwin client.

My issue is that the command line argument "-c command" is not
recognized. For example, if I run (from Cygwin)

psql -h localhost -p 5432 -d $database postgres -c "select count(*)
from  $table_name"

I receive the following output:

psql: warning: extra command-line argument "-c" ignored
psql: warning: extra command-line argument "select count(*) from
$table_name" ignored
Welcome to psql 8.3.8, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

Warning: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.

End output.

If I put the query in a file and run the file from the command line,
then it works fine.  Furthermore, it appears I have all the necessary
priviledges since I can create/delete/modify tables in the database -
as long as the sql code is in a script file.

I will add that this code runs on an XP-32Bit 8.2 install and I
recently installed PostgreSQL on the XP-64Bit machine.

Thanks for any insight you can provide.



Re: -c argument not recognized

From
Thom Brown
Date:
2009/11/10 Antonio Ruggiero <aruggiero02@gmail.com>:
> I am running PostgresSQL 8.3.8 on windows XP-64Bit.  I am using psql
> client from the PostgreSQL installation and not the Cygwin client.
>
> My issue is that the command line argument "-c command" is not
> recognized. For example, if I run (from Cygwin)
>
> psql -h localhost -p 5432 -d $database postgres -c "select count(*)
> from  $table_name"
>
> I receive the following output:
>
> psql: warning: extra command-line argument "-c" ignored
> psql: warning: extra command-line argument "select count(*) from
> $table_name" ignored
> Welcome to psql 8.3.8, the PostgreSQL interactive terminal.
>
> Type:  \copyright for distribution terms
>       \h for help with SQL commands
>       \? for help with psql commands
>       \g or terminate with semicolon to execute query
>       \q to quit
>
> Warning: Console code page (437) differs from Windows code page (1252)
>         8-bit characters might not work correctly. See psql reference
>         page "Notes for Windows users" for details.
>
> End output.
>
> If I put the query in a file and run the file from the command line,
> then it works fine.  Furthermore, it appears I have all the necessary
> priviledges since I can create/delete/modify tables in the database -
> as long as the sql code is in a script file.
>
> I will add that this code runs on an XP-32Bit 8.2 install and I
> recently installed PostgreSQL on the XP-64Bit machine.
>
> Thanks for any insight you can provide.
>

It might be because you're specifying it after the database name which
should be the last parameter, and which you've already specified with
-d anyway.  Try: psql -h localhost -p 5432 -d $database -c "select
count(*)

Regards

Thom

Re: -c argument not recognized

From
Antonio Ruggiero
Date:
On Nov 10, 4:56 pm, thombr...@gmail.com (Thom Brown) wrote:
> 2009/11/10 Antonio Ruggiero <aruggier...@gmail.com>:
>
>
>
>
>
> > I am running PostgresSQL 8.3.8 on windows XP-64Bit.  I am using psql
> > client from the PostgreSQL installation and not the Cygwin client.
>
> > My issue is that the command line argument "-c command" is not
> > recognized. For example, if I run (from Cygwin)
>
> > psql -h localhost -p 5432 -d $database postgres -c "select count(*)
> > from  $table_name"
>
> > I receive the following output:
>
> > psql: warning: extra command-line argument "-c" ignored
> > psql: warning: extra command-line argument "select count(*) from
> > $table_name" ignored
> > Welcome to psql 8.3.8, the PostgreSQL interactive terminal.
>
> > Type:  \copyright for distribution terms
> >       \h for help with SQL commands
> >       \? for help with psql commands
> >       \g or terminate with semicolon to execute query
> >       \q to quit
>
> > Warning: Console code page (437) differs from Windows code page (1252)
> >         8-bit characters might not work correctly. See psql reference
> >         page "Notes for Windows users" for details.
>
> > End output.
>
> > If I put the query in a file and run the file from the command line,
> > then it works fine.  Furthermore, it appears I have all the necessary
> > priviledges since I can create/delete/modify tables in the database -
> > as long as the sql code is in a script file.
>
> > I will add that this code runs on an XP-32Bit 8.2 install and I
> > recently installed PostgreSQL on the XP-64Bit machine.
>
> > Thanks for any insight you can provide.
>
> It might be because you're specifying it after the database name which
> should be the last parameter, and which you've already specified with
> -d anyway.  Try: psql -h localhost -p 5432 -d $database -c "select
> count(*)
>
> Regards
>
> Thom
>
> --
> Sent via pgsql-general mailing list (pgsql-gene...@postgresql.org)
> To make changes to your subscription:http://www.postgresql.org/mailpref/pgsql-general- Hide quoted text -
>
> - Show quoted text -

You suggestion did work when I run this

$ psql -h localhost -p 5432 -d $database -c "select count(*) from
client_claim_file" postgres

However, if I now force the username command line argument then I can
recover the original form that worked with 8.2, that is:

>psql -h localhost -p 5432 -d $database -U postgres -c "select count(*) from $tablename"

Thanks for your help - never would have thought about the order of
command line arguments.  FYI, the reason I was trying to recover the
original form was that I have an alias for "psql -h localhost -p 5432 -
d $database -U postgres".


Re: -c argument not recognized

From
Jasen Betts
Date:
On 2009-11-10, Antonio Ruggiero <aruggiero02@gmail.com> wrote:
> I am running PostgresSQL 8.3.8 on windows XP-64Bit.  I am using psql
> client from the PostgreSQL installation and not the Cygwin client.
>
> My issue is that the command line argument "-c command" is not
> recognized. For example, if I run (from Cygwin)
>
> psql -h localhost -p 5432 -d $database postgres -c "select count(*)
> from  $table_name"

On windows you must put the command line arguments in the correct order
(see the documentation for details of correct order)

On linux (and I assume other POSIX) the order is not critical.

windows command-line sucks anyway, so using pipes or temporary files
for the commands is probably a better solution, especially if the
commands are determined at runtime.