将视图从SAP SQL Anywhere移植到Postgres

时间:2018-10-08 10:51:54

标签: postgresql quoted-identifier

我目前正在研究Postgres,作为SAP SQL Anywhere的可能替代方案。我已经成功地将开发数据库(700个表)移植到Postgres中,现在正尝试在Postgres DB中创建一些等效视图。

以下内容:

CREATE VIEW "SYS_Authorisation_BO_Access_View"
AS
SELECT     ROW_NUMBER() OVER (ORDER BY t1.OID) AS OID, t1.OID as BusinessObjectTypeID, t1.TypeName, t1.AccessType, t1.GroupID, a.Authorised, t1.defaultboauthorisation, COALESCE (a.Authorised, t1.defaultboauthorisation) 
                      AS FinalAuthorisation
FROM         "SYS_Authorisation_BO_Access" AS ab INNER JOIN
                      "SYS_Authorisation" AS a ON a.OID = ab.OID RIGHT OUTER JOIN
                          (SELECT     o.OID, o.TypeName, at.AccessType, g.OID as GroupID, 
                                                   CASE at.accesstype WHEN 'C' THEN g.defaultbocreateauthorisation WHEN 'M' THEN g.defaultbomodifyauthorisation WHEN 'D' THEN g.defaultbodeleteauthorisation
                                                    END AS defaultboauthorisation
                            FROM          XPObjectType AS o CROSS JOIN
                                                       (SELECT     'C' AS AccessType
                                                         UNION
                                                         SELECT     'D' AS AccessType
                                                         UNION
                                                         SELECT     'M' AS AccessType) AS at CROSS JOIN
                                                   SYS_Group AS g) AS t1 ON ab.BusinessObjectTypeID = t1.OID AND ab.AccessType = t1.AccessType AND a.GroupID = t1.GroupID

产生以下错误:

ERROR:  column a.oid does not exist
LINE 6:                       "SYS_Authorisation" AS a ON a.OID = ab...

1 个答案:

答案 0 :(得分:0)

好的,事实证明这是全部区分大小写的。 SAP SQL不区分大小写,而Postgres不区分大小写。

以下经修改的SQL有效:

CREATE VIEW "SYS_Authorisation_BO_Access_View"
AS
SELECT     ROW_NUMBER() OVER (ORDER BY t1."OID") AS "OID", t1."OID" as "BusinessObjectTypeID", t1."TypeName", t1."AccessType", t1."GroupID", a."Authorised", t1."DefaultBOAuthorisation", COALESCE (a."Authorised", t1."DefaultBOAuthorisation") 
                      AS "FinalAuthorisation"
FROM         "SYS_Authorisation_BO_Access" AS ab INNER JOIN
                      "SYS_Authorisation" AS a ON a."OID" = ab."OID" RIGHT OUTER JOIN
                          (SELECT     o."OID", o."TypeName", at."AccessType", g."OID" as "GroupID", 
                                                   CASE at."AccessType" WHEN 'C' THEN g."DefaultBOCreateAuthorisation" WHEN 'M' THEN g."DefaultBOModifyAuthorisation" WHEN 'D' THEN g."DefaultBODeleteAuthorisation"
                                                    END AS "DefaultBOAuthorisation"
                            FROM          "XPObjectType" AS o CROSS JOIN
                                                       (SELECT     'C' AS "AccessType"
                                                         UNION
                                                         SELECT     'D' AS "AccessType"
                                                         UNION
                                                         SELECT     'M' AS "AccessType") AS at CROSS JOIN
                                                   "SYS_Group" AS g) AS t1 ON ab."BusinessObjectTypeID" = t1."OID" AND ab."AccessType" = t1."AccessType" AND a."GroupID" = t1."GroupID"