我想使用pgx
(通过sqlc
)copyfrom
功能,条件为COPY FROM WHERE,如下所示:
(this条件取自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;
在pgx中有没有办法做到这一点?谢谢。
1条答案
按热度按时间ndh0cuux1#
是的,有一种方法可以做到这一点。一个人可以使用
func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (CommandTag, error)
.您可以在测试用例中找到使用示例:
只需使用
WHERE
语句扩展COPY foo FROM STDIN ...
即可。