简体   繁体   中英

KubeCTL with Postgres query doesn't work and throws "LINE 1: select * FROM "employees" where employeeData::text like someSampleHere;"

The field employeeData is of type json .

Consider the query:

select * FROM "employees" where employeeData::text like '%someSampleHere%'

When I'm running the query inside Postgres it works perfect and I get the rows that I'm asking for.

However when I use it with KubeCTL and running this query outside of the PG App

psql -d employess_db -U postgres -c 'select * FROM "employees" where employeeData::text like 'someSampleHere';'

PG throws

ERROR:  syntax error at or near "%"
LINE 1: select * FROM "employees" where employeeData::text like %someSampleHere%;

How can we fix it?

Sounds like a quoting problem to me. You neglected to show your actual kubectl command line in your question, but this works for me without any errors:

kubectl exec postgres-pod -- psql -U postgres -d employees_db \
  -c "select * from \"employees\" where employeeData::text like '%someSampleHere%'"

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