Lists: | pgsql-general |
---|
From: | Susan Hurst <susan(dot)hurst(at)brookhurstdata(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Space Stalker in SQL Output |
Date: | 2018-06-27 19:09:23 |
Message-ID: | 8ad8301badea6566622771129517cf02@mail.brookhurstdata.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
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(dot)hurst(at)brookhurstdata(dot)com
Mobile: 314-486-3261
From: | Jerry Sievers <gsievers19(at)comcast(dot)net> |
---|---|
To: | Susan Hurst <susan(dot)hurst(at)brookhurstdata(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Space Stalker in SQL Output |
Date: | 2018-06-27 19:38:53 |
Message-ID: | 87zhzgauk2.fsf@jsievers.enova.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Susan Hurst <susan(dot)hurst(at)brookhurstdata(dot)com> writes:
> 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`
Get in the habit of including -A which gets rid of alignment padding in
psql output.
As in...
shellvar=`psql -Atqc 'select froboz;'` $db
HTH
--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres(dot)consulting(at)comcast(dot)net
p: 312.241.7800
From: | Susan Hurst <susan(dot)hurst(at)brookhurstdata(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Space Stalker in SQL Output |
Date: | 2018-06-27 19:45:55 |
Message-ID: | eccb720e4e62d02dccafdc12ad46ec6d@mail.brookhurstdata.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Wow! The -A option worked perfectly!
Thanks for the syntax lesson Steve and Jerry!
Sue
---
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Susan E Hurst
Principal Consultant
Brookhurst Data LLC
Email: susan(dot)hurst(at)brookhurstdata(dot)com
Mobile: 314-486-3261
On 2018-06-27 14:38, Jerry Sievers wrote:
> Susan Hurst <susan(dot)hurst(at)brookhurstdata(dot)com> writes:
>
>> 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`
>
> Get in the habit of including -A which gets rid of alignment padding in
> psql output.
>
> As in...
>
> shellvar=`psql -Atqc 'select froboz;'` $db
>
> HTH
From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | susan(dot)hurst(at)brookhurstdata(dot)com, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Space Stalker in SQL Output |
Date: | 2018-06-27 23:08:48 |
Message-ID: | 85cd0303-4816-e501-c75b-5adb8b7fd668@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On 06/27/2018 12:45 PM, Susan Hurst wrote:
> Wow! The -A option worked perfectly!
>
> Thanks for the syntax lesson Steve and Jerry!
If you are going to be doing lots of scripting with Postgres, you might
want to take a look here: https://github.com/jconway/shebang
HTH,
Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development