pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Pepe TD Vo <pepevo@yahoo.com>
To: Christopher Browne <cbbrowne@gmail.com>
Cc: Pgsql-admin <pgsql-admin@postgresql.org>
Cc: Pgsql-general <pgsql-general@postgresql.org>
Subject: Re: create batch script to import into postgres tables
Date: Thu, 18 Jun 2020 16:00:33 -0700
Message-ID: <57eddc72-9278-9e17-3df2-3cd8bb40e82d@aklaver.com> (raw)
In-Reply-To: <889466258.267016.1592510085000@mail.yahoo.com>
References: <866581879.1147164.1592317256828.ref@mail.yahoo.com>
	<866581879.1147164.1592317256828@mail.yahoo.com>
	<1f5f4fd6-ad22-4823-c922-17a021c2c0d7@aklaver.com>
	<74046808.1129536.1592317823808@mail.yahoo.com>
	<3625e291-8456-3831-6205-2d73232bcd1e@aklaver.com>
	<1718146430.1151531.1592319564343@mail.yahoo.com>
	<CAFNqd5U_9N6pagHYivRxN1hrq-YrE=gD3n3W76fzORojXMZcVg@mail.gmail.com>
	<1761277119.1163490.1592322138731@mail.yahoo.com>
	<732982585.145357.1592493607620@mail.yahoo.com>
	<cd3af30c-41a2-4df1-d41e-6316b692227e@aklaver.com>
	<1814718409.184531.1592498400894@mail.yahoo.com>
	<4d5841c4-9a6c-0e20-2c05-c21d3d3942df@aklaver.com>
	<889466258.267016.1592510085000@mail.yahoo.com>

On 6/18/20 12:54 PM, Pepe TD Vo wrote:
>>>psql -d production  -U postgres -c 'select count(*) from cell_per';
> Null display is "NULL".
>    count
> -------
>      68
> (1 row)
> 
> you can do this once you are in psql. But if you are running from shell 
> script, it will be an error
> 
>  >>What error messages do you get?
> 
> my shell script is:
> @echo off
> C:\Program Files\PostgreSQL\11\bin\psql -U PSmasteruser  -d PSCIDR -h 
> hostname.amazonaws.com -p 5432 -c "select count(*) from tableA;"
> pause
> 
> the error I have is 'C:\Program' is not recognized as an internal or 
> external command, operable program or batch file.
> 
> I even surround the path in quotes because of space.
> @echo off
> cmd /c ""C:\Program Files\PostgreSQL\11\bin\psql" -U PSmasteruser -d 
> PSCIDR -h hostname.amazonaws.com -p 5432 -c "select count(*) from tableA;"
> pause

Not sure how quoting works in Windows shell scripts, but pretty sure the 
above has unbalanced quotes.


> 
> error is: 'C:\Program Files\PostgreSQL\11\bin\psql: illegal option -- u
> 
> when I put -P Password123 (or fully qualified password=Password123)

I would recommend spending some time here:

https://www.postgresql.org/docs/12/app-psql.html

to see what the options are. Hint: -P is not the option for password.

> 
> it gives me another error "pset: unknow option: Password123
> psql: could not set printing parameter "Password123"

It is the option for pset as the error message says.

> 
> I can connect from psql shell fine when it prompt hostname, username 
> (but connect to postgres not to PSmasteruser, PSmasteruser username set 
> up for aws maintenance postgres database, someone did, not me and the 
> password is same on both).  Once I'm in psql and I can change to PSCIDR 
> instance fine and run select count(*) from tableA;
> 
> 
> 
> **
> *Bach-Nga
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (32+ messages)  latest in thread

Message-ID: <57eddc72-9278-9e17-3df2-3cd8bb40e82d@aklaver.com>
Permalink:  ../57eddc72-9278-9e17-3df2-3cd8bb40e82d@aklaver.com/
Also on:    postgresql.org/message-id/57eddc72-9278-9e17-3df2-3cd8bb40e82d@aklaver.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: adrian.klaver@aklaver.com, pepevo@yahoo.com, cbbrowne@gmail.com, pgsql-general@postgresql.org
  Subject: Re: create batch script to import into postgres tables
  In-Reply-To: <57eddc72-9278-9e17-3df2-3cd8bb40e82d@aklaver.com>

* 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