我正在尝试更新表中的大约6000行,但我的查询永远不会完成。 我已将数据更新到临时表中并使用连接来更新行。 这在Sql Server中运行得非常快,但在Postgresql中它永远不会完成。 我正在更新大约40列。 这是我正在运行的sql。
UPDATE "STG_magento_de".sales_flat_order
SET customer_id = b.customer_id
,created_at = b.created_at
,updated_at = b.updated_at
,coupon_code = b.coupon_code
,box_id = b.box_id
,beautytrends_glossydots = b.beautytrends_glossydots
,billing_address_id = b.billing_address_id
,shipping_address_id = b.shipping_address_id
,base_discount_amount = b.base_discount_amount
,base_discount_canceled = b.base_discount_canceled
,base_discount_invoiced = b.base_discount_invoiced
,base_discount_refunded = b.base_discount_refunded
,base_grand_total = b.base_grand_total
,base_shipping_amount = b.base_shipping_amount
,base_shipping_canceled = b.base_shipping_canceled
,base_shipping_invoiced = b.base_shipping_invoiced
,base_shipping_refunded = b.base_shipping_refunded
,base_shipping_tax_amount = b.base_shipping_tax_amount
,base_shipping_tax_refunded = b.base_shipping_tax_refunded
,base_subtotal = b.base_subtotal
,base_subtotal_canceled = b.base_subtotal_canceled
,base_subtotal_invoiced = b.base_subtotal_invoiced
,base_tax_amount = b.base_tax_amount
,base_tax_canceled = b.base_tax_canceled
,base_tax_invoiced = b.base_tax_invoiced
,base_tax_refunded = b.base_tax_refunded
,base_to_global_rate = b.base_to_global_rate
,base_to_order_rate = b.base_to_order_rate
,base_total_canceled = b.base_total_canceled
,base_total_invoiced = b.base_total_invoiced
,base_total_invoiced_cost = b.base_total_invoiced_cost
,base_total_offline_refunded = b.base_total_offline_refunded
,base_total_online_refunded = b.base_total_online_refunded
,base_total_paid = b.base_total_paid
,base_total_qty_ordered = b.base_total_qty_ordered
,base_total_refunded = b.base_total_refunded
,increment_id = b.increment_id
,order_type = b.order_type
,STATUS = b.STATUS
,is_chargerun = b.is_chargerun
,chargeback_flag = b.chargeback_flag
,gift_message_id = b.gift_message_id
,dispatch = b.dispatch
FROM "STG_magento_de".sales_flat_order a
JOIN "STG_magento_de".sales_flat_order_temp b ON a.entity_id = b.entity_id
答案 0 :(得分:3)
请注意,目标表不得出现在from_list中,除非您打算进行自联接(在这种情况下,它必须在from_list中显示别名)。
(强调我的)
所以你真的想要:
UPDATE "STG_magento_de".sales_flat_order
SET customer_id = b.customer_id,
....
from sales_flat_order_temp b --<< do NOT repeat the target table here
where "STG_magento_de".sales_flat_order = b.entity_id`
无关,但是:你应该真的避免使用那些可怕的引用标识符。他们比他们的价值要麻烦得多。