# JDBC plugin: Doesn't work when the table name contains a hyphen

**URL:** <https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278>\
**Category:** Logstash\
**Created:** [December 11, 2018, 3:23am UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278 "2018-12-11T03:23:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prodrg](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@prodrg](https://discuss.elastic.co/u/prodrg)\
**Post date:** [December 11, 2018, 3:23am UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278/1 "2018-12-11T03:23:40Z")

</div>

Hi guys,

I am using the JDBC plugin and I need to extract info from a Postgresql database. The issue I'm having is that the table I want to grab info has a hyphen on the name, and this is causing a conflict.

This is my pipeline:

```auto
input {
  jdbc {
    jdbc_connection_string => "jdbc:postgresql://servermani.com:5432/hg-sertak"
    jdbc_user => "username"
    jdbc_password => "${postgres_pass}"
    jdbc_driver_library => "/usr/share/logstash/sql/postgresql-42.2.5.jar"
    jdbc_driver_class => "org.postgresql.Driver"
    #parameters => { "table_name" => "table-name" }
    statement => "SELECT * from table-name"
  }
}
output {
  stdout { codec => json_lines }
}

```

And these are the error lines I'm getting:

```auto
[2018-12-11T03:21:45,130][INFO][logstash.runner] Starting Logstash {"logstash.version"=>"6.5.2"}
[2018-12-11T03:21:52,363][INFO][logstash.pipeline] Starting pipeline {:pipeline_id=>"postgresql", "pipeline.workers"=>1, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2018-12-11T03:21:53,787][INFO][logstash.pipeline] Pipeline started successfully {:pipeline_id=>"postgresql", :thread=>"#<Thread:0x9a502c4 run>"}
[2018-12-11T03:22:00,792][ERROR][logstash.inputs.jdbc] Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "-"
  Position: 17: SELECT * from table-name
[2018-12-11T03:22:00,930][WARN][logstash.inputs.jdbc] Exception when executing JDBC query {:exception=>#<Sequel::DatabaseError: Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "-"
   Position: 17>}
[2018-12-11T03:22:01,919][INFO][logstash.pipeline] Pipeline has terminated {:pipeline_id=>"postgresql", :thread=>"#<Thread:0x9a502c4 run>"}

```

How can I escape the hyphen?

Thank you

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [December 11, 2018, 9:59am UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278/2 "2018-12-11T09:59:01Z")

</div>

[https://www.google.co.uk/search?q=postgres+hyphen+table+name+sql&oq=postgres+hyphen+table+name+sql&aqs=chrome..69i57.14943j0j8&sourceid=chrome&ie=UTF-8](https://www.google.co.uk/search?q=postgres+hyphen+table+name+sql&oq=postgres+hyphen+table+name+sql&aqs=chrome..69i57.14943j0j8&sourceid=chrome&ie=UTF-8)

---

<div class="post-metadata">

**Author:** ![prodrg](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@prodrg](https://discuss.elastic.co/u/prodrg)\
**Post date:** [December 11, 2018, 2:18pm UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278/3 "2018-12-11T14:18:34Z")

</div>

Mmm, I have already tried putting "", `` or even single quotes, and the following errors appeared:

```auto
[2018-12-11T03:22:00,792][ERROR][logstash.inputs.jdbc] Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "`"
  Position: 17: SELECT * from `table-name`
[2018-12-11T03:22:00,792][ERROR][logstash.inputs.jdbc] Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "\"
  Position: 17: SELECT * from \"table-name\"
[2018-12-11T03:22:00,792][ERROR][logstash.inputs.jdbc] Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "'table-name'"
  Position: 17: SELECT * from 'table-name'

```

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [December 11, 2018, 2:21pm UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278/4 "2018-12-11T14:21:17Z")

</div>

Have you tried single quotes in the plugin setting...  
`statement => 'SELECT * from "table-name"'`

---

<div class="post-metadata">

**Author:** ![prodrg](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@prodrg](https://discuss.elastic.co/u/prodrg)\
**Post date:** [December 12, 2018, 4:27pm UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278/5 "2018-12-12T16:27:09Z")

</div>

Yes, this works, but unfortunately, by a matter of requirements for the Logstash pipeline, I'm forced to use double quotes for the value part instead of the single ones. I forgot to indicate that, my apologies.

I ended using the statement\_path option, as it is a cleaner way to execute the query, and helpful for bigger queries.

Thank you.

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [December 12, 2018, 4:57pm UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278/6 "2018-12-12T16:57:37Z")

</div>

😄  
I was going to suggest the `statement_path` setting next.

---

<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:** [January 9, 2019, 4:57pm UTC](https://discuss.elastic.co/t/jdbc-plugin-doesnt-work-when-the-table-name-contains-a-hyphen/160278/7 "2019-01-09T16:57:43Z")

</div>

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