# Logstash sql\_last\_value not compare correctly

**URL:** <https://discuss.elastic.co/t/logstash-sql-last-value-not-compare-correctly/294398>\
**Category:** Logstash\
**Created:** [January 14, 2022, 10:29am UTC](https://discuss.elastic.co/t/logstash-sql-last-value-not-compare-correctly/294398 "2022-01-14T10:29:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikram\_singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikram_singh/32/66490_2.png) [@vikram\_singh](https://discuss.elastic.co/u/vikram_singh)\
**Post date:** [January 14, 2022, 10:29am UTC](https://discuss.elastic.co/t/logstash-sql-last-value-not-compare-correctly/294398/1 "2022-01-14T10:29:05Z")

</div>

Hi,  
I am using logstash to insert data from sql to index.  
I am using a date column **compare\_date** to compare for sql\_last\_value field.  
When I am running, logstash automatically reduce 1 day from **compare\_date**.  
Suppose my **compare\_date** is 2021-10-01, it automatically change it to 2021-09-30.  
Here is my query:

```auto
SELECT * FROM(
select month,year, TO_DATE('01-'||LPAD(month,2,'0')||'-'||year,'dd-MM-YYYY') as compare_date
FROM my_table GROUP BY year,month ORDER BY year, month Asc
)
WHERE compare_date > :sql_last_value AND compare_date < NOW()

```

if month is 10 and year is 2021 than it change compare\_date to 2021-09-30

---

<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:** [January 14, 2022, 3:02pm UTC](https://discuss.elastic.co/t/logstash-sql-last-value-not-compare-correctly/294398/2 "2022-01-14T15:02:29Z")

</div>

I wonder if you are hitting [this](https://github.com/logstash-plugins/logstash-input-jdbc/issues/293) 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:** [February 11, 2022, 3:03pm UTC](https://discuss.elastic.co/t/logstash-sql-last-value-not-compare-correctly/294398/3 "2022-02-11T15:03:24Z")

</div>

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