apache / apache/datafusion-sqlparser-rs

PostgreSQL CREATE TRIGGER parses execution arguments as data types

未关闭
#2,446 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
3.5k
派生
772
平均合并
4 天 9 小时
30 天内合并 PR
17

描述

## Problem

PostgreSQL trigger execution arguments are literal string constants passed to the trigger function through `TG_ARGV`. The PostgreSQL parser currently routes the `EXECUTE FUNCTION` / `EXECUTE PROCEDURE` tail through `FunctionDesc` / `OperateFunctionArg`, whose arguments represent function declaration data types. As a result, a valid trigger argument is parsed as though it were a data-type declaration and fails at the first literal.

Observed with `sqlparser = 0.62` and `PostgreSqlDialect`.

## Minimal reproductions

```sql
CREATE TRIGGER t_audit
AFTER INSERT ON t
FOR EACH ROW
EXECUTE FUNCTION audit_row('api_key');
```

The legacy PostgreSQL spelling fails the same way:

```sql
CREATE TRIGGER t_audit
AFTER INSERT ON t
FOR EACH ROW
EXECUTE PROCEDURE audit_row('api_key');
```

Both report:

```text
Expected: a data type name, found: 'api_key'
```

The corresponding zero-argument forms parse successfully:

```sql
EXECUTE FUNCTION audit_row();
EXECUTE PROCEDURE audit_row();
```

PostgreSQL accepts both complete trigger statements with the string argument.

## Expected behavior

- Both trigger statements parse successfully under `PostgreSqlDialect`.
- The AST retains `'api_key'` as an execution-time literal/expression (or a trigger-specific argument representation), not as an `OperateFunctionArg` data-type declaration.
- Multiple trigger arguments remain ordered and round-trip through `Display`.
- Function/procedure declaration arguments continue to use the existing data-type-oriented representation.

PostgreSQL's grammar requires trigger arguments here to be string constants. A trigger-specific argument field would therefore also be reasonable if using the general expression AST would accept syntax PostgreSQL itself rejects.

## Downstream context

This was found in Goldziher/scythe#238. Scythe statically parses schema DDL to build a catalog. Triggers do not add catalog state, so scythe skips them after parsing; it still needs sqlparser to accept the valid statement so one trigger does not abort parsing of the entire schema.

I can prepare a focused parser/AST test or implementation once the preferred AST representation is confirmed.

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 PostgreSqlDialect 的触发器解析开始,跟踪 EXECUTE FUNCTION 和 EXECUTE PROCEDURE 路径经过 FunctionDesc 和 OperateFunctionArg 的处理。为一个及多个有序字符串参数添加针对性的 parser 和 Display 测试,并将声明参数保留为数据类型;当两种形式都能成功解析并往返转换时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
postgresql, rust
领域
compilers, databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。