My JDBC SQL statement have both single (') and double (") quote, how do i supply it in JDBC input plugin?

My input looks like

input {
jdbc {
jdbc_connection_string => "jdbc:redshift://infa-iidiq-cluster-qa1.ctd4xsffelb3.us-west-2.redshift.amazonaws.com:5439/iidiqdatabase"
jdbc_user => ""
jdbc_password => ""
jdbc_validate_connection => true
jdbc_driver_library => "RedshiftJDBC42-1.2.10.1009.jar"
jdbc_driver_class => "com.amazon.redshift.jdbc42.Driver"
schedule => "*/3 * * * *"
statement => 'SELECT log_entry_id, CASE WHEN task_status = 'SUCCESS' THEN 'INFO' WHEN task_status = 'FAILED' THEN 'ERROR' WHEN task_status = 'WARNINGS' THEN 'WARN' END AS "log_level", 'activity' AS "log_type" FROM xyz.abc WHERE tracking_col >:sql_last_value ORDER BY tracking_col ASC'
use_column_value => true
tracking_column => tracking_col
last_run_metadata_path => "metadata/logstash_jdbc_last_run"
}
}

But due to usage of both " and ' plugin throwing error.

My SQL statement
SELECT log_entry_id,
CASE
WHEN task_status = 'SUCCESS'
THEN 'INFO'
WHEN task_status = 'FAILED'
THEN 'ERROR'
WHEN task_status = 'WARNINGS'
THEN 'WARN'
END AS "log_level",
'activity' AS "log_type"
FROM xyz.abc
WHERE tracking_col >:sql_last_value
ORDER BY tracking_col ASC

Any help will be appreciated.

Do you really need to mix single and double quotes in this case? Anyway, Logstash fairly recently introduced escape sequence support for the pipeline config files but it must be explicitly enabled. See https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html#_escape_sequences.

2 Likes

Thanks for the quick solution, let me try and validate

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