Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/plugin/out_mysql_bulk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def write(chunk)
data = format_proc.call(tag, time, data, max_lengths)
values << Mysql2::Client.pseudo_bind(values_template, data)
end
sql = "INSERT INTO #{table} (#{@column_names.join(',')}) VALUES #{values.join(',')}"
sql = "INSERT INTO `#{table}` (#{@column_names.map { |colname| "`#{colname}`" }.join(',')}) VALUES #{values.join(',')}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column names may legally include a backtick character themselves.

Identifier quote characters can be included within an identifier if you quote the identifier. If the character to be included within the identifier is the same as that used to quote the identifier itself, then you need to double the character. The following statement creates a table named a`b that contains a column named c"d:

CREATE TABLE `a``b` (`c"d` INT);

So in addition to wrapping names in backticks, you will also have to replace backticks inside the names with double backticks.

sql += @on_duplicate_key_update_sql if @on_duplicate_key_update

log.info "bulk insert values size (table: #{table}) => #{values.size}"
Expand Down