# Is it possible to use a varchar/string for jdbc sql\_last\_value?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845>\
**Category:** Logstash\
**Created:** [November 3, 2016, 11:17am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845 "2016-11-03T11:17:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [November 3, 2016, 11:17am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/1 "2016-11-03T11:17:07Z")

</div>

I've already tested the `sql_last_value` with `integer` and `datetime` type of fields in my `jdbc` plugin and it's working perfectly.

I'm just curios, is there any possibility of using a `varchar/string` type of field, in order to update the `sql_last_value` time to time.

Any help could be appreciated.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 7, 2016, 5:53pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/2 "2016-11-07T17:53:18Z")

</div>

I don't see why it wouldn't work. Have you tried?

---

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [November 8, 2016, 4:32am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/3 "2016-11-08T04:32:16Z")

</div>

@magnusbaeck thanks for the reply.

I thought it wouldn't work since if i'm having a string how will I be able to do the below check for the last `sql_last_value`:

`idString > :sql_last_value`

It cannot check right unless it's an `integer` or a `timestamp`.? Am I wrong

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 8, 2016, 6:49am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/4 "2016-11-08T06:49:21Z")

</div>

Again, why are you assuming that the \< and \> operators don't work for strings? Have you tried?

Even if it doesn't work I'm sure there's some way of comparing strings in your SQL dialect. Your query doesn't have to have the form `column_name > :sql_last_value`; you could say `UPPER(column_name) > UPPER(:sql_last_value)` or whatever makes sense for you.

---

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [November 8, 2016, 3:51pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/5 "2016-11-08T15:51:43Z")

</div>

Thanks again @magnusbaeck.

> [@magnusbaeck](#):
>
> Your query doesn't have to have the form column\_name \> :sql\_last\_value; you could say UPPER(column\_name) \> UPPER(:sql\_last\_value)

Now lets say i'm having a `string` type column called `name` and before running the `logstash` conf, `sql_last_value` is empty. I'm having values as `text1, text2, text3..` under the column `name`.

So if I'm going to upload the db records through `logstash` to the index with some way of comparing strings in the SQL dialect, what if there're two records having the same string value for the `name` column ? Will `sql_last_value` compare two of them and assume it as a duplicate?

What does `UPPER(column_name)` mean in `UPPER(column_name) > UPPER(:sql_last_value)`?

`> :` in the SQL dialect means to check if the value is greater than the existing `sql_last_value` isn't it ? So how can it compare when it comes to a string?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 8, 2016, 4:18pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/6 "2016-11-08T16:18:26Z")

</div>

> So if I'm going to upload the db records through logstash to the index with some way of comparing strings in the SQL dialect, what if there're two records having the same string value for the name column ? Will sql\_last\_value compare two of them and assume it as a duplicate?

The number of rows with duplicate values is irrelevant. All rows where the column in question is greater than the saved sql\_last\_value string will be included.

> What does UPPER(column\_name) mean in UPPER(column\_name) \> UPPER(:sql\_last\_value)?

It was an example so it doesn't really matter, but I was thinking of MySQL where UPPER() returns the uppercase version of the argument. When comparing two uppercased strings you're effectively turning the normally case-sensitive comparison into a case-insentitive one.

> `> :` in the SQL dialect means to check if the value is greater than the existing sql\_last\_value isn't it ?

Yes.

> So how can it compare when it comes to a string?

Are you not understanding the concept of comparing strings (as opposed to comparing numbers), or what is unclear?

---

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [November 8, 2016, 4:30pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/7 "2016-11-08T16:30:18Z")

</div>

> [@magnusbaeck](#):
>
> Are you not understanding the concept of comparing strings (as opposed to comparing numbers)

yes that's right @magnusbaeck . That's where i'm pretty confused. 😕

---

<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:** [July 6, 2017, 4:30am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-a-varchar-string-for-jdbc-sql-last-value/64845/8 "2017-07-06T04:30:43Z")

</div>

Closed on July 6, 2017, 4:30am UTC


