I would like to use pgx
(via sqlc
) copyfrom
feature with a COPY FROM WHERE condition as such:
(this condition was taken from a working rule on INSERT):
WHERE (EXISTS ( SELECT *
FROM asns
WHERE merchantId IS NOT DISTINCT FROM NEW.merchantId
AND return_provider IS NOT DISTINCT FROM NEW.return_provider
AND barcode IS NOT DISTINCT FROM NEW.barcode
AND carrier IS NOT DISTINCT FROM NEW.carrier
AND tracking_number IS NOT DISTINCT FROM NEW.tracking_number
AND customer_email IS NOT DISTINCT FROM NEW.customer_email
AND order_id IS NOT DISTINCT FROM NEW.order_id
AND order_name IS NOT DISTINCT FROM NEW.order_name
AND order_number IS NOT DISTINCT FROM NEW.order_number
AND return_line_item_id IS NOT DISTINCT FROM NEW.return_line_item_id
AND rma IS NOT DISTINCT FROM NEW.rma
AND sku IS NOT DISTINCT FROM NEW.sku)) DO INSTEAD NOTHING;
Is there a way to do this in pgx? Thank you.
Yes, there is a way of doing this. One can use
func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (CommandTag, error)
.You can find the example of usage in test cases:
Just extend
COPY foo FROM STDIN ...
withWHERE
statement.