# Error with \_sql query with curl

**URL:** https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232
**Category:** Elasticsearch
**Tags:** eql-elastic-query-language
**Created:** [January 24, 2022, 1:35pm UTC](https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232 "2022-01-24T13:35:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rodri.gz](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@rodri.gz](https://discuss.elastic.co/u/rodri.gz)
#### Post date: [January 24, 2022, 1:35pm UTC](https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232/1 "2022-01-24T13:35:29Z")

</div>

Hello !

I am trying to cast a query to my Elasticsearch cluster. When I use where with numeric fields, everything works correctly, but when I try to use it with text fields, problems appear.

What would be the correct syntax?

correct example:

```auto
curl -XPOST -u elastic:xxxxxxx -k https://yyyyyyyyyyyy:9200/_sql?format=csv -H "Content-Type: application/json" -d '
{
"query": "SELECT * FROM \"yyyyy-lllll-ultimo-dia\" WHERE phone_tlf=1",
"fetch_size": 10000
}'

```

Error example:

```auto
curl -XPOST -u elastic:xxxxxxx -k https://yyyyyyyyyyyy:9200/_sql?format=csv -H "Content-Type: application/json" -d '
{
"query": "SELECT * FROM \"aaaa-bbb-last-day\" WHERE employee-user=AB97C-2",
"fetch_size": 10000
}'

```

Could someone tell me where I have to put the " or, " or nothing?

It would be a great help.  
Thanks in advance!

---

<div class="post-metadata">

### Author: ![bogdan.pintea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bogdan.pintea/32/45740_2.png) [@bogdan.pintea](https://discuss.elastic.co/u/bogdan.pintea)
#### Post date: [January 27, 2022, 7:45am UTC](https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232/2 "2022-01-27T07:45:36Z")

</div>

@rodri.gz , you'll want to [escape the string literal with single quotes](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-lexical-structure.html#sql-syntax-literals): `...WHERE employee-user='AB97C-2'`

---

<div class="post-metadata">

### Author: ![rodri.gz](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@rodri.gz](https://discuss.elastic.co/u/rodri.gz)
#### Post date: [January 28, 2022, 8:37am UTC](https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232/3 "2022-01-28T08:37:47Z")

</div>

First of all thanks for the help.

Secondly, I have tried with the format that you mention and it detects the value as a column.

```auto
curl -XPOST -u xxx:yyyy-k https://zzzzzzzzzzz:9200/_sql?format=csv -H "Content-Type: application/json" -d '
 {
	"query": "SELECT * FROM \"abc\" WHERE Provincia='Alicante' ",
	"fetch_size": 10000
  }'

```

response:

```auto
{"error":{"root_cause":[{"type":"verification_exception","reason":"Found 1 problem\nline 1:56: Unknown column [Alicante]"}],"type":"verification_exception","reason":"Found 1 problem\nline 1:56: Unknown column [Alicante]"}

```

I have also tried with the format "field"='value' but it doesn't work either, any advice?

---

<div class="post-metadata">

### Author: ![bogdan.pintea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bogdan.pintea/32/45740_2.png) [@bogdan.pintea](https://discuss.elastic.co/u/bogdan.pintea)
#### Post date: [February 2, 2022, 4:14pm UTC](https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232/4 "2022-02-02T16:14:57Z")

</div>

You're passing the content of the query to curl with `-d'`, so the next occurring `'` (like those framing your literal) might interfere with the argument passing and not be transmitted as such to Elasticsearch. You might need to escape the inner simple quotes.

---

<div class="post-metadata">

### Author: ![rodri.gz](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@rodri.gz](https://discuss.elastic.co/u/rodri.gz)
#### Post date: [February 3, 2022, 10:05am UTC](https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232/5 "2022-02-03T10:05:57Z")

</div>

i will try it! thank you

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 3, 2022, 10:06am UTC](https://discuss.elastic.co/t/error-with-sql-query-with-curl/295232/6 "2022-03-03T10:06:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
