The best way to insert multidimensional numeric array #1891
-
I have a field in the database that is NUMERIC[][] and in the Go code it is represented as [][]string. But when I try to insert the values using the conn.CopyFrom and pgx.CopyFromSlice methods I get the error below.
What is the best way to insert a multi-dimensional NUMERIC array? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In PostgreSQL there are two formats that most values can be encoded, text and binary. For normal queries, such as produced by However, the COPY protocol requires all values to be encoded in the same format. pgx's Try master and it should work. |
Beta Was this translation helpful? Give feedback.
In PostgreSQL there are two formats that most values can be encoded, text and binary. For normal queries, such as produced by
Query
andExec
, PostgreSQL allows choosing the format per value. When pgx detects your underlying data is a string it simply passes it to PostgreSQL as-is.However, the COPY protocol requires all values to be encoded in the same format. pgx's
CopyFrom
only supports the binary format. It already tried to parse strings to values that can then be encoded into the binary format. But it didn't handle types such as[]string
that aren't strings but that can be encoded as text and then parsed and converted to binary. It now does.Try master and it should work.