#2385·pgx

Multidimensional array flattened when using CopyFrom instead of Exec+Insert

Author: rrb3942Created Sep 16, 2025Updated Jul 1, 2026
Labelsbug

Describe the bug When using CopyFrom to insert a string value of a postgres formatted multidimensional array, the array is getting flattened. If inserted via Exec the dimensions are properly persevered.

My specific scenario is bulk loading from a csv with fields containing postgres formatted arrays into a text[][] column.

To Reproduce Steps to reproduce the behavior:

In postgres:

 create table array_test ( array_col text[][] );
go
package main

import (
        "context"
        "fmt"
        "os"

        "github.com/jackc/pgx/v5"
)

func main() {
        conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))

        if err != nil {
                fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
                os.Exit(1)
        }

        defer conn.Close(context.Background())

        multi := "{{one,two,three},{four,five,six}}"
        rows := [][]any{
                        {multi},
                }

        //will insert as {{one,two,three},{four,five,six}}
        _, err = conn.Exec(context.Background(), "insert into array_test (array_col) values ($1)", multi)

        if err != nil {
                fmt.Println(err)
                os.Exit(1)
        }

        //will insert as {one,two,three,four,five,six}
        _, err = conn.CopyFrom(context.Background(), pgx.Identifier{"array_test"}, []string{"array_col"}, pgx.CopyFromRows(rows))

        if err != nil {
                fmt.Println(err)
                os.Exit(1)
        }

        fmt.Println("insert ok")
}

Expected behavior Array dimensions to be preserved and identical behavior to Exec+Insert.

Actual behavior Array dimensions flattened.

Version

  • Go: create table array_test ( array_col text[][] );
  • PostgreSQL: PostgreSQL 17.6 (Debian 17.6-1.pgdg12+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
  • pgx: v5.7.6

Additional context psql with COPY or \COPY from the csv works as expected.