# JDBC Input Plugin: extracting the statement as a field in Logstash?

**URL:** <https://discuss.elastic.co/t/jdbc-input-plugin-extracting-the-statement-as-a-field-in-logstash/167439>\
**Category:** Logstash\
**Created:** [February 7, 2019, 11:50am UTC](https://discuss.elastic.co/t/jdbc-input-plugin-extracting-the-statement-as-a-field-in-logstash/167439 "2019-02-07T11:50:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rozling](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rozling/32/16401_2.png) [@rozling](https://discuss.elastic.co/u/rozling)\
**Post date:** [February 7, 2019, 11:50am UTC](https://discuss.elastic.co/t/jdbc-input-plugin-extracting-the-statement-as-a-field-in-logstash/167439/1 "2019-02-07T11:50:02Z")

</div>

We have our JDBC input working well, and we're trying to see if we can log our SQL statement with the query result.

Here is our config:

```
input {
  jdbc {
    jdbc_driver_library => "/usr/share/java/mysql.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://localhost:3306/db_name"
    jdbc_user => "username"
    jdbc_password => "password"                                                                                             
    schedule => "* * * * *"
    statement => "SELECT NOW()"
  }
}

```

We tried adding:

```
    add_field => {
      "statement" => "%{statement}"
    }

```

But this doesn't seem to work 😕

---

<div class="post-metadata">

**Author:** ![admlko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/admlko/32/21787_2.png) [@admlko](https://discuss.elastic.co/u/admlko)\
**Post date:** [February 7, 2019, 12:24pm UTC](https://discuss.elastic.co/t/jdbc-input-plugin-extracting-the-statement-as-a-field-in-logstash/167439/2 "2019-02-07T12:24:26Z")

</div>

I think the only possible way to achieve this is to copy the statement as is to the new field. You cannot refer to the config values with %{} notation, because that is for the fields in the event itself, not in the config.  
So my suggestion is to duplicate the statement in the add\_field part.

---

<div class="post-metadata">

**Author:** ![rozling](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rozling/32/16401_2.png) [@rozling](https://discuss.elastic.co/u/rozling)\
**Post date:** [February 7, 2019, 12:38pm UTC](https://discuss.elastic.co/t/jdbc-input-plugin-extracting-the-statement-as-a-field-in-logstash/167439/3 "2019-02-07T12:38:00Z")

</div>

That would work too 🙂

Thanks!

---

<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 7, 2019, 12:38pm UTC](https://discuss.elastic.co/t/jdbc-input-plugin-extracting-the-statement-as-a-field-in-logstash/167439/4 "2019-03-07T12:38:01Z")

</div>

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