简体   繁体   中英

psql in bash very strange error

I Have a problem with a psql query in bash.

I really don't know why the PSQL understands the value HUB is a Column.

psql -q -A -h Some_host -U User -d datashema -p 1111 -t -f query.txt -c 'SELECT id, text FROM great_201704 WHERE id = 10 and text = 'HUB' ;'

ERROR: column "hub" does not exist in great_201704

You read your single quotes as if they nest:

-c 'SELECT id, text FROM great_201704 WHERE id = 10 and text = 'HUB' ;'
   ^---------------------------------1--------------------------------^
                                                               ^-2-^

Bash reads them as two single quoted string with a literal between them:

-c 'SELECT id, text FROM great_201704 WHERE id = 10 and text = 'HUB' ;'
   ^------------------------------1----------------------------^
                                                                   ^2-^

This is equivalent to not having single quotes around HUB , which is why psql thinks its a column.

The easiest way to embed one set of quotes in another string is to just use two different types of quotes:

psql -q -A -h Some_host -U User -d datashema -p 1111 -t -f query.txt \
    -c "SELECT id, text FROM great_201704 WHERE id = 10 and text = 'HUB' ;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM