以下代码在SQL Server上正常运行。但是当我在Postgres上尝试它时,它给了我一个错误:表名"安全"指定不止一次
我尝试了别名,但没有帮助。任何人都可以帮忙吗?
UPDATE security
SET
security.review_required_flag = True,
security.issuer_id = sag_diff."ISSUER_ID",
security.business_line = sag_diff."BUSINESS_LINE",
security.cusip = sag_diff."CUSIP",
FROM security
INNER JOIN sag_diff
ON (security.product_id = sag_diff."PRODUCT_ID")
AND(security.msd_id = sag_diff."MSD_ID")
AND(security.osp = sag_diff."OSP")
WHERE security.issuer_id <> sag_diff."ISSUER_ID"
OR security.business_line <> sag_diff."BUSINESS_LINE"
OR security.cusip <> sag_diff."CUSIP"
OR security.industry_sector <> sag_diff."INDUSTRY_SECTOR"
答案 0 :(得分:0)
在Postgres中,如果要在FROM子句中使用更新的表,则应为它们提供不同的别名。但是,在您的情况下,您只需要FROM子句中的第二个表:
UPDATE security
SET
review_required_flag = True,
issuer_id = sag_diff."ISSUER_ID",
business_line = sag_diff."BUSINESS_LINE",
cusip = sag_diff."CUSIP"
FROM sag_diff
WHERE security.product_id = sag_diff."PRODUCT_ID"
AND security.msd_id = sag_diff."MSD_ID"
AND security.osp = sag_diff."OSP"
AND (security.issuer_id <> sag_diff."ISSUER_ID"
OR security.business_line <> sag_diff."BUSINESS_LINE"
OR security.cusip <> sag_diff."CUSIP"
OR security.industry_sector <> sag_diff."INDUSTRY_SECTOR")