# How to write a multi-line SQL in logstash pipelines

**URL:** <https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182>\
**Category:** Logstash\
**Created:** [May 25, 2020, 4:24pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182 "2020-05-25T16:24:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tenet\_testuser1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenet_testuser1/32/67526_2.png) [@tenet\_testuser1](https://discuss.elastic.co/u/tenet_testuser1)\
**Post date:** [May 25, 2020, 4:24pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/1 "2020-05-25T16:24:16Z")

</div>

Hello,

So far, I am able to write a single line SQL in logstash pipelines and it's working fine.

However, How do I write multiline SQL with single-quotes (') in the SQL? I tried with a backslash for continuation, but the pipeline is not being invoked when I look at the logs.

For instance:

How do I write the following sql in pipeline.

Select a.col1,b.col2  
from tab1 a, tab2 b  
where a.col3='something'  
and a.col4=b.col4;

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 25, 2020, 6:04pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/2 "2020-05-25T18:04:42Z")

</div>

Why do you want to have a multiline SQL?

A string can contain newlines, so I see no reason why something like

```
statement => "SELECT * from songs
              where artist = :favorite_artist"

```

would not work.

If the pipeline is not running then logstash almost certainly logged an error. What do you see in the logs?

---

<div class="post-metadata">

**Author:** ![tenet\_testuser1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenet_testuser1/32/67526_2.png) [@tenet\_testuser1](https://discuss.elastic.co/u/tenet_testuser1)\
**Post date:** [May 25, 2020, 6:17pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/3 "2020-05-25T18:17:45Z")

</div>

You're using abind variable. How do I pass values? Can you provide a working example please

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 25, 2020, 7:51pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/4 "2020-05-25T19:51:00Z")

</div>

Why not just do this?

```
Select a.col1,b.col2 from tab1 a, tab2 b where a.col3='something' and a.col4=b.col4;

```

Are you getting an error when you do this?

---

<div class="post-metadata">

**Author:** ![tenet\_testuser1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenet_testuser1/32/67526_2.png) [@tenet\_testuser1](https://discuss.elastic.co/u/tenet_testuser1)\
**Post date:** [May 25, 2020, 10:16pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/5 "2020-05-25T22:16:40Z")

</div>

I guess you want me to type the SQL in a single line... If so, it's not ideal in all situations.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 25, 2020, 10:59pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/6 "2020-05-25T22:59:00Z")

</div>

> [@tenet\_testuser1](#):
>
> I guess you want me to type the SQL in a single line..

No, I do not care how many lines you spread the SQL across. As I said before, if the pipeline is not running then logstash almost certainly logged an error. What do you see in the logs?

---

<div class="post-metadata">

**Author:** ![tenet\_testuser1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenet_testuser1/32/67526_2.png) [@tenet\_testuser1](https://discuss.elastic.co/u/tenet_testuser1)\
**Post date:** [May 26, 2020, 12:44am UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/7 "2020-05-26T00:44:33Z")

</div>

The pipeline is not running because it's multi line. All other pipelines that are single line SQL are running fine

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 26, 2020, 4:04pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/8 "2020-05-26T16:04:20Z")

</div>

Last chance... what do you see in the logs?

---

<div class="post-metadata">

**Author:** ![tenet\_testuser1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenet_testuser1/32/67526_2.png) [@tenet\_testuser1](https://discuss.elastic.co/u/tenet_testuser1)\
**Post date:** [May 27, 2020, 4:28pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/9 "2020-05-27T16:28:07Z")

</div>

Sorry My friend. Was busy with some other issue.

Thanks. I was able to figure out the issue.

Maybe useful for someone in the future...

I left the index\_type and document\_type the same and just changed the id in the pipeline. The first pipeline has multisql, the one that followed had a single line.

So I think it was getting overwritten. So I did not see any errors also.  
Upon taking a closer look I figured this issue and corrected it.

It worked perfectly. Including predicates with quotes (').

closing the issue.

---

<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:** [June 24, 2020, 4:28pm UTC](https://discuss.elastic.co/t/how-to-write-a-multi-line-sql-in-logstash-pipelines/234182/10 "2020-06-24T16:28:08Z")

</div>

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