# How to use current date to determine table name for jdbc\_input query?

**URL:** <https://discuss.elastic.co/t/how-to-use-current-date-to-determine-table-name-for-jdbc-input-query/144400>\
**Category:** Logstash\
**Created:** [August 14, 2018, 8:06pm UTC](https://discuss.elastic.co/t/how-to-use-current-date-to-determine-table-name-for-jdbc-input-query/144400 "2018-08-14T20:06:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [August 14, 2018, 8:06pm UTC](https://discuss.elastic.co/t/how-to-use-current-date-to-determine-table-name-for-jdbc-input-query/144400/1 "2018-08-14T20:06:19Z")

</div>

I have a database with a table per month for data:

table\_01, table\_02, ..., table\_12

Is it possible to have logstash construct the table name at runtime, and use it in the query?

---

<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:** [August 14, 2018, 8:46pm UTC](https://discuss.elastic.co/t/how-to-use-current-date-to-determine-table-name-for-jdbc-input-query/144400/2 "2018-08-14T20:46:12Z")

</div>

You can pass parameters to the statement using the parameters option. You might be able to set one of the parameters using an [environment variable](https://www.elastic.co/guide/en/logstash/current/environment-variables.html).

---

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [August 15, 2018, 3:10pm UTC](https://discuss.elastic.co/t/how-to-use-current-date-to-determine-table-name-for-jdbc-input-query/144400/3 "2018-08-15T15:10:32Z")

</div>

It's invalid sql to use a parameter for the table name, and the date replacement doesn't get performed for the parameter value anyway.

---

<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:** [August 15, 2018, 7:28pm UTC](https://discuss.elastic.co/t/how-to-use-current-date-to-determine-table-name-for-jdbc-input-query/144400/4 "2018-08-15T19:28:00Z")

</div>

The only other thing I can think of is to use statement\_filepath instead of statement and deal with it outside of logstash.

---

<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:** [September 12, 2018, 7:28pm UTC](https://discuss.elastic.co/t/how-to-use-current-date-to-determine-table-name-for-jdbc-input-query/144400/5 "2018-09-12T19:28:00Z")

</div>

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