# Bool From JDBC

**URL:** <https://discuss.elastic.co/t/bool-from-jdbc/280850>\
**Category:** Logstash\
**Created:** [August 9, 2021, 8:34pm UTC](https://discuss.elastic.co/t/bool-from-jdbc/280850 "2021-08-09T20:34:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wwalker](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wwalker](https://discuss.elastic.co/u/wwalker)\
**Post date:** [August 9, 2021, 8:34pm UTC](https://discuss.elastic.co/t/bool-from-jdbc/280850/1 "2021-08-09T20:34:51Z")

</div>

Is it possible to query a SQL database and, if the results have a column value matching a given string, return a boolean?

I am wanting to query a table whose results will return multiple rows. I want to check the column value for each returned row and, if any matches `ex*`, that is anything that starts with ex, return the value bool value of `true`. I don't need to know how many times it matches `ex*`, just whether or not it matches at least once.

---

<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 9, 2021, 8:53pm UTC](https://discuss.elastic.co/t/bool-from-jdbc/280850/2 "2021-08-09T20:53:45Z")

</div>

Use a COUNT WHERE LIKE and then compare the resulting number with zero. Not sure if you can do the compare in the SQL statement.

---

<div class="post-metadata">

**Author:** ![wwalker](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wwalker](https://discuss.elastic.co/u/wwalker)\
**Post date:** [August 19, 2021, 6:22pm UTC](https://discuss.elastic.co/t/bool-from-jdbc/280850/3 "2021-08-19T18:22:02Z")

</div>

After some digging, I had success using the following query.

```auto
SELECT CAST(COUNT(1) AS BIT) FROM tablename WHERE user LIKE 'gates%' AND id = :id

```

This returns a 1 or 0 that logstash interprets as a bool.

---

<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 16, 2021, 6:22pm UTC](https://discuss.elastic.co/t/bool-from-jdbc/280850/4 "2021-09-16T18:22:47Z")

</div>

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