Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -803,6 +803,40 @@ func TestConnCopyFromAutomaticStringConversion(t *testing.T) {
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
// https://github.com/jackc/pgx/discussions/1891
|
||||
func TestConnCopyFromAutomaticStringConversionArray(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||
defer cancel()
|
||||
|
||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||
defer closeConn(t, conn)
|
||||
|
||||
mustExec(t, conn, `create temporary table foo(
|
||||
a numeric[]
|
||||
)`)
|
||||
|
||||
inputRows := [][]interface{}{
|
||||
{[]string{"42"}},
|
||||
{[]string{"7"}},
|
||||
{[]string{"8", "9"}},
|
||||
{[][]string{{"10", "11"}, {"12", "13"}}},
|
||||
}
|
||||
|
||||
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a"}, pgx.CopyFromRows(inputRows))
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, len(inputRows), copyCount)
|
||||
|
||||
// Test reads as int64 and flattened array for simplicity.
|
||||
rows, _ := conn.Query(ctx, "select * from foo")
|
||||
nums, err := pgx.CollectRows(rows, pgx.RowTo[[]int64])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, [][]int64{{42}, {7}, {8, 9}, {10, 11, 12, 13}}, nums)
|
||||
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
func TestCopyFromFunc(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user