(t *testing.T)
| 322 | } |
| 323 | |
| 324 | func TestConnCopyFromEnum(t *testing.T) { |
| 325 | t.Parallel() |
| 326 | |
| 327 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 328 | defer cancel() |
| 329 | |
| 330 | conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) |
| 331 | defer closeConn(t, conn) |
| 332 | |
| 333 | tx, err := conn.Begin(ctx) |
| 334 | require.NoError(t, err) |
| 335 | defer tx.Rollback(ctx) |
| 336 | |
| 337 | _, err = tx.Exec(ctx, `drop type if exists color`) |
| 338 | require.NoError(t, err) |
| 339 | |
| 340 | _, err = tx.Exec(ctx, `drop type if exists fruit`) |
| 341 | require.NoError(t, err) |
| 342 | |
| 343 | _, err = tx.Exec(ctx, `create type color as enum ('blue', 'green', 'orange')`) |
| 344 | require.NoError(t, err) |
| 345 | |
| 346 | _, err = tx.Exec(ctx, `create type fruit as enum ('apple', 'orange', 'grape')`) |
| 347 | require.NoError(t, err) |
| 348 | |
| 349 | // Obviously using conn while a tx is in use and registering a type after the connection has been established are |
| 350 | // really bad practices, but for the sake of convenience we do it in the test here. |
| 351 | for _, name := range []string{"fruit", "color"} { |
| 352 | typ, err := conn.LoadType(ctx, name) |
| 353 | require.NoError(t, err) |
| 354 | conn.TypeMap().RegisterType(typ) |
| 355 | } |
| 356 | |
| 357 | _, err = tx.Exec(ctx, `create temporary table foo( |
| 358 | a text, |
| 359 | b color, |
| 360 | c fruit, |
| 361 | d color, |
| 362 | e fruit, |
| 363 | f text |
| 364 | )`) |
| 365 | require.NoError(t, err) |
| 366 | |
| 367 | inputRows := [][]any{ |
| 368 | {"abc", "blue", "grape", "orange", "orange", "def"}, |
| 369 | {nil, nil, nil, nil, nil, nil}, |
| 370 | } |
| 371 | |
| 372 | copyCount, err := tx.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f"}, pgx.CopyFromRows(inputRows)) |
| 373 | require.NoError(t, err) |
| 374 | require.EqualValues(t, len(inputRows), copyCount) |
| 375 | |
| 376 | rows, err := tx.Query(ctx, "select * from foo") |
| 377 | require.NoError(t, err) |
| 378 | |
| 379 | var outputRows [][]any |
| 380 | for rows.Next() { |
| 381 | row, err := rows.Values() |
nothing calls this directly
no test coverage detected