leafo/pgmoon

encode_array not support escape_literal

gzliudan opened this issue · 2 comments

local encode_array = require("pgmoon.arrays").encode_array
local my_array = {“abcd”,“1234”}
pg:query("insert into some_table (text_array_column) values(" .. pg:escape_literal(encode_array(my_array)) .. ")")

leafo commented

encode_array returns a string that already escaped for interpolation into a query. You should not call escape_literal on the result, that would escape the array as if it was a string.

Thanks, I write a udf which converts string to array to resolve this problem.