我想添加我的CSV文件到postgreSQL。但是每当我尝试连接它时,显示错误:
[logstash.outputs(错误)。jdbc
][主要][a4f714a30e2d2cae8e83b3c2d215c3537fe40dca0495ca92cc2f50a93ba8088a]JDBC -异常。没有失败的{:exception=># <"%">
它是My Config.conf文件:
input {
file {
path => "C:/Users/Desktop/InputData12.csv"
start_position => "beginning"
codec => plain
}
}
filter {
csv {
separator => ","
columns => ["inputdata","metric","source_table","output_column_alias","method"]
}
}
output {
jdbc {
connection_string => "jdbc:postgresql://hostname:5432/database"
username => "username"
password => "password"
driver_jar_path => "C:/Users/Downloads/lib/postgresql-42.5.1.jar"
driver_class => "org.postgresql.Driver"
statement => "INSERT INTO csv_to_postgresql (inputdata,metric,source_table,output_column_alias,method) VALUES (%{inputdata},%{metric},%{source_table},%{output_column_alias},%{method})"
}
}
我希望得到一个不同的错误(JDBC - Statement没有参数)。有两种类型的语句。如果设置"unsafe_statement =>true"那么输出将显示SQL语句。如果你没有设置,那么你应该使用
statement => [
"INSERT INTO csv_to_postgresql (inputdata,metric,source_table,output_column_alias,method) VALUES (?, ?, ?, ?, ?)",
"%{inputdata}",
"%{metric}",
"%{source_table}",
"%{output_column_alias}",
"%{method})"
]
,在这种情况下,输出将把所有参数输出到语句中。设置unsafe_statement的开销可能比第二种方法更大。