Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kuL97-0003Xe-SI for pgsql-general@arkaria.postgresql.org; Tue, 29 Dec 2020 19:59:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kuL96-0002yu-Rc for pgsql-general@arkaria.postgresql.org; Tue, 29 Dec 2020 19:59:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kuL96-0002yh-Fk for pgsql-general@lists.postgresql.org; Tue, 29 Dec 2020 19:59:04 +0000 Received: from 024-182-127-154.biz.spectrum.com ([24.182.127.154] helo=mail.brookhurstdata.net) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kuL92-00029d-S6 for pgsql-general@lists.postgresql.org; Tue, 29 Dec 2020 19:59:03 +0000 Received: from mail.brookhurstdata.net (mail.brookhurstdata.net [10.1.5.12]) by mail.brookhurstdata.net (Postfix) with ESMTP id 8FA6288901D for ; Tue, 29 Dec 2020 13:58:59 -0600 (CST) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_035780966cd6131a6caf438c6ce112a2" Date: Tue, 29 Dec 2020 13:58:59 -0600 From: Susan Hurst To: pgsql-general@lists.postgresql.org Subject: Re: copy command - something not found Organization: Brookhurst Data LLC Reply-To: susan.hurst@brookhurstdata.com Mail-Reply-To: susan.hurst@brookhurstdata.com In-Reply-To: References: <97194eb185caab667101ca543b28df00@mail.brookhurstdata.net> Message-ID: <6e225170cb1d4bf52fab2001db22d581@mail.brookhurstdata.net> X-Sender: susan.hurst@brookhurstdata.com User-Agent: Roundcube Webmail/RCMAIL_VERSION List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_035780966cd6131a6caf438c6ce112a2 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 Thank you for the reminders, John. I changed my .z file extension to .tmp and removed the trailing / from my pre-defined directory path. I'm still getting the same results as before though after changing the .z file extension to .tmp. The ${DBNAME} and ${HOSTNAME} variables are input at run time. Here is usage format: ### Usage: copy_data.sh rfc_name db_name [db_host] Note: [db_host] (hostname) is optional with default localhost, which is what I'm using in this particular case. My actual input at execution time was this: ./install_db.sh RFC-00001 stp This script calls the copy_data.sh script. ${CSVPATH} is: /home/dbzone/stp/rfc_db/RFC-00001 (after removing the trailing /) --- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Susan E Hurst Principal Consultant Brookhurst Data LLC Email: susan.hurst@brookhurstdata.com Mobile: 314-486-3261 On 2020-12-29 13:20, John McKown wrote: > Can't really tell. You might want to post the output of the "printenv" command to show us what the shell variables you are using have in them. Oh, does ${CSVPATH} end in a slash? If it is something like "~/mycsvs" then ${CSVPATH}copycmd.z will expand to "~/mycsvscopycmd.z". Most "PATH" environment variables don't end in a /, perhaps you need "${CSVPATH}/copycmd.z" ? Also, as an aside. most UNIX files which end in .z are compressed, IIRC. Make sure the contents of the file are plain text. > > On Tue, Dec 29, 2020 at 1:12 PM Susan Hurst wrote: > >> I am trying to use the copy command from a csv files using a UNIX shell >> script but something is 'not found'...I can't figure out what is 'not >> found'. Below is my command from the shell script, the executed command, >> the content of the csv file and the output from trying to execute the >> command. >> >> Clearly, the file is being read but I can't figure out what is not >> found. BTW, the column names in the stg.bar_active table match the names >> and order in the first row of the csv file. What should I be looking >> for? >> >> Thanks for your help! >> >> Sue >> >> ##-- shell script command >> psql -d ${DBNAME} -U ${DBNAME} -h ${HOSTNAME} -c < ${CSVPATH}copycmd.z >> >> ##-- executed command >> "copy stg.bar_active from >> '/home/dbzone/stp/rfc_db/RFC-00001/RFC-00001_copy_bar_active.csv' >> delimiter ',' CSV HEADER;" >> >> ##-- content of .csv file >> schema_name,table_name,table_alias ...(this is the header >> row) >> chief,source_systems,ssys >> chief,lookup_categories,lcat >> chief,lookup_data,ldat >> >> ##-- output from terminal window >> /home/dbzone/stp/rfc_db/RFC-00001/RFC-00001_copy_bar_active.csv: >> schema_name,table_name,table_alias: not found >> /home/dbzone/stp/rfc_db/RFC-00001/RFC-00001_copy_bar_active.csv: >> chief,source_systems,ssys: not found >> /home/dbzone/stp/rfc_db/RFC-00001/RFC-00001_copy_bar_active.csv: >> chief,lookup_categories,lcat: not found >> /home/dbzone/stp/rfc_db/RFC-00001/RFC-00001_copy_bar_active.csv: >> chief,lookup_data,ldat: not found >> >> ##-- select version(); >> PostgreSQL 11.9 on amd64-portbld-freebsd12.1, compiled by FreeBSD clang >> version 8.0.1 (tags/RELEASE_801/final 366581) (based on LLVM 8.0.1), >> 64-bit >> >> -- >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> Susan E Hurst >> Principal Consultant >> Brookhurst Data LLC >> Email: susan.hurst@brookhurstdata.com >> Mobile: 314-486-3261 --=_035780966cd6131a6caf438c6ce112a2 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

Thank you for the reminders, John.  I changed my .z file extension = to .tmp and removed the trailing / from my pre-defined directory path.

I'm still getting the same results as before though after changing the = =2Ez file extension to .tmp.

The ${DBNAME} and ${HOSTNAME} variables are input at run time. Here is u= sage format:
### Usage:         &nb= sp;      copy_data.sh rfc_name db_name [db_host]
N= ote: [db_host] (hostname) is optional with default localhost, which is what= I'm using in this particular case.

My actual input at execution time was this:   ./install_db.sh = RFC-00001 stp
This script calls the copy_data.sh script.

${CSVPATH} is:  /home/dbzone/stp/rfc_db/RFC-00001   (afte= r removing the trailing /)

---
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Susan E Hurst Principal Consultant Brookhurst Data LLC Email: susan.hurst@brookhurstdata.com Mobile: 314-486-3261

On 2020-12-29 13:20, John McKown wrote:

Can't really tell. You might want to post the output of the "printenv"= command to show us what the shell variables  you are using have in th= em. Oh, does ${CSVPATH} end in a slash? If it is something like "~/mycsvs" = then ${CSVPATH}copycmd.z will expand to "~/mycsvscopycmd.z". Most  "PA= TH" environment variables  don't end in a /, perhaps you need "${CSVPA= TH}/copycmd.z" ? Also, as an aside. most UNIX files which end in .z ar= e compressed, IIRC.  Make sure the contents of the file  are plai= n text.

On Tue, Dec 29, 2020 at 1:12 PM Susan= Hurst <susan.hurst@br= ookhurstdata.com> wrote:
I am trying to use the copy = command from a csv files using a UNIX shell
script but something is = 'not found'...I can't figure out what is 'not
found'. Below is my co= mmand from the shell script, the executed command,
the content of th= e csv file and the output from trying to execute the
command.
<= br /> Clearly, the file is being read but I can't figure out what is not found. BTW, the column names in the stg.bar_active table match the nam= es
and order in the first row of the csv file. What should I be look= ing
for?

Thanks for your help!

Sue

##-- shell script command
psql -d ${DBNAME} -U ${DBNAME} -h ${HOST= NAME} -c < ${CSVPATH}copycmd.z

##-- executed command
"= copy stg.bar_active from
'/home/dbzone/stp/rfc_db/RFC-00001/RFC-0000= 1_copy_bar_active.csv'
delimiter ',' CSV HEADER;"

##-- c= ontent of .csv file
schema_name,table_name,table_alias    &= nbsp;       ...(this is the header
row)
chief,s= ource_systems,ssys
chief,lookup_categories,lcat
chief,lookup_da= ta,ldat

##-- output from terminal window
/home/dbzone/stp= /rfc_db/RFC-00001/RFC-00001_copy_bar_active.csv:
schema_name,table_n= ame,table_alias: not found
/home/dbzone/stp/rfc_db/RFC-00001/RFC-0000= 1_copy_bar_active.csv:
chief,source_systems,ssys: not found
/h= ome/dbzone/stp/rfc_db/RFC-00001/RFC-00001_copy_bar_active.csv:
chief= ,lookup_categories,lcat: not found
/home/dbzone/stp/rfc_db/RFC-00001/= RFC-00001_copy_bar_active.csv:
chief,lookup_data,ldat: not found

##-- select version();
PostgreSQL 11.9 on amd64-portbld-free= bsd12.1, compiled by FreeBSD clang
version 8.0.1 (tags/RELEASE_801/f= inal 366581) (based on LLVM 8.0.1),
64-bit

--
~~~= ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Susan E Hurst
Princip= al Consultant
Brookhurst Data LLC
Email: susan.hurst@brookhurstdata.com
Mobile= : 314-486-3261


--=_035780966cd6131a6caf438c6ce112a2--