Home > Software engineering >  KubeCTL with Postgres query doesn't work and throws "LINE 1: select * FROM "employees
KubeCTL with Postgres query doesn't work and throws "LINE 1: select * FROM "employees

Time:04-12

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 ?

CodePudding user response:

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%'"
  • Related