pgx icon indicating copy to clipboard operation
pgx copied to clipboard

How to call pgx.Tx CopyFrom with sql.Tx

Open firstone opened this issue 1 year ago • 2 comments

pgx.Tx supports CopyFrom but there seems to be no way to use it from sql driver. Raw call will only produce pgx.Conn object but I don't see a way to call CopyFrom via sql.Tx

firstone avatar Feb 09 '24 15:02 firstone

I don't know of any way to get a reference to a pgx object directly from a *sql.Tx. You could probably call Raw and BeginTx on the same *sql.Conn to start a transaction and be able to get the underlying *pgx.Conn -- but obviously that's a bit messy and error prone.

jackc avatar Feb 10 '24 23:02 jackc

FYI, I confirmed this does work by calling BeginTx, creating a temp table in the tx, and then doing CopyFrom into that temp table via Raw on the same conn (not referencing the tx directly).

bushrod avatar Aug 12 '24 19:08 bushrod