Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYFos-0001Nc-0U for pgsql-general@arkaria.postgresql.org; Wed, 27 Jun 2018 19:09:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fYFon-0002IY-Hd for pgsql-general@arkaria.postgresql.org; Wed, 27 Jun 2018 19:09:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYFon-0002IP-6O for pgsql-general@lists.postgresql.org; Wed, 27 Jun 2018 19:09:29 +0000 Received: from 24-182-127-154.static.stls.mo.charter.com ([24.182.127.154] helo=mail.brookhurstdata.net) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fYFoj-0005DQ-Fa for pgsql-general@postgresql.org; Wed, 27 Jun 2018 19:09:27 +0000 Received: from mail.brookhurstdata.net (mail.brookhurstdata.net [10.1.5.12]) by mail.brookhurstdata.net (Postfix) with ESMTP id 4141E88901D for ; Wed, 27 Jun 2018 14:09:24 -0500 (CDT) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Wed, 27 Jun 2018 14:09:23 -0500 From: Susan Hurst To: pgsql-general@postgresql.org Subject: Space Stalker in SQL Output Organization: Brookhurst Data LLC Reply-To: susan.hurst@brookhurstdata.com Mail-Reply-To: susan.hurst@brookhurstdata.com Message-ID: <8ad8301badea6566622771129517cf02@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 Why would a psql statement insert a leading space into the output, which is a single integer value? The leading space caused my job call to fail elsewhere in the same shell script as the psql call. Here is the anonymized version of the psql call to assign a value to a shell script variable: IDz=`psql -d proddb -U produser -h 10.9.999.99 -p 99900 -t < last_id.sql` The output is simply a max(id) value, which is defined as an integer data type in the source table column. The output looked like this (notice the leading space before the integer value): echo “IDz =${IDz} IDz =’ 100’ The last_id.sql itself is simply: select max(id) from prodtable; I'm using: PostgreSQL 9.5.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16), 64-bit I fixed the output in the shell script with a tr command but why should that be necessary? What is causing the space to be prepended to integer value? ID=`echo ${IDz} | tr -d ''` IDz =’100’ Knowing the root cause of the space stalker would be most helpful. Thanks for your help! Sue -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Susan E Hurst Principal Consultant Brookhurst Data LLC Email: susan.hurst@brookhurstdata.com Mobile: 314-486-3261