确定libpg_query中的枚举常量

时间:2018-08-10 00:51:42

标签: postgresql parsing node-gyp pg-query

当我升级到最新版本的libpgquery(https://github.com/lfittl/libpg_query)时,许多objtype数字在节点上更改了。

我正在尝试找到一种确定映射的编程方式,以便可以在表示形式之间来回切换。当前,似乎某些objtype数字来自原始来源中的ObjectType枚举数据结构,但有些不是。

例如,以这两个语句为例:

COMMENT ON CAST (text AS int4) IS 'Allow casts from text to int4';
COMMENT ON TABLE my_schema.my_table IS 'Employee Information';

CommentStmt根据经验得出一个OBJECT_CAST,因为该节点具有objtype=5,这是正确的!另一个节点产生OBJECT_STATISTIC_EXT的原因是objtype=37,但是我们知道它实际上应该是OBJECT_TABLE

如果您在下面的源代码中查找,则不完全是枚举的顺序。知道为什么会这样吗?我不确定节点类型是否会更改objtype,因为我想它们会在整个源中共享。

src/include/nodes/parsenodes.h内的

https://doxygen.postgresql.org/parsenodes_8h.html#a842c5e2e69277690b064bf363c017980

{
     OBJECT_ACCESS_METHOD,
     OBJECT_AGGREGATE,
     OBJECT_AMOP,
     OBJECT_AMPROC,
     OBJECT_ATTRIBUTE,           /* type's attribute, when distinct from column */
     OBJECT_CAST,
     OBJECT_COLUMN,
     OBJECT_COLLATION,
     OBJECT_CONVERSION,
     OBJECT_DATABASE,
     OBJECT_DEFAULT,
     OBJECT_DEFACL,
     OBJECT_DOMAIN,
     OBJECT_DOMCONSTRAINT,
     OBJECT_EVENT_TRIGGER,
     OBJECT_EXTENSION,
     OBJECT_FDW,
     OBJECT_FOREIGN_SERVER,
     OBJECT_FOREIGN_TABLE,
     OBJECT_FUNCTION,
     OBJECT_INDEX,
     OBJECT_LANGUAGE,
     OBJECT_LARGEOBJECT,
     OBJECT_MATVIEW,
     OBJECT_OPCLASS,
     OBJECT_OPERATOR,
     OBJECT_OPFAMILY,
     OBJECT_POLICY,
     OBJECT_PROCEDURE,
     OBJECT_PUBLICATION,
     OBJECT_PUBLICATION_REL,
     OBJECT_ROLE,
     OBJECT_ROUTINE,
     OBJECT_RULE,
     OBJECT_SCHEMA,
     OBJECT_SEQUENCE,
     OBJECT_SUBSCRIPTION,
     OBJECT_STATISTIC_EXT,
     OBJECT_TABCONSTRAINT,
     OBJECT_TABLE,
     OBJECT_TABLESPACE,
     OBJECT_TRANSFORM,
     OBJECT_TRIGGER,
     OBJECT_TSCONFIGURATION,
     OBJECT_TSDICTIONARY,
     OBJECT_TSPARSER,
     OBJECT_TSTEMPLATE,
     OBJECT_TYPE,
     OBJECT_USER_MAPPING,
     OBJECT_VIEW
 } ObjectType;

objtype甚至是这里吗?

感谢您的帮助!目前,我正在考虑手动为每个objtype编写测试用例,并从经验上发现它们。

0 个答案:

没有答案