apache / apache/datafusion-sqlparser-rs

PostgreSQL CREATE TRIGGER parses execution arguments as data types

Aberta
#2,446 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Rust
Estrelas
3.5k
Forks
772
Merge médio
4d 9h
PRs com merge (30d)
17

Descrição

## 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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Comece na análise de triggers de PostgreSqlDialect e rastreie os caminhos EXECUTE FUNCTION e EXECUTE PROCEDURE por FunctionDesc e OperateFunctionArg. Adicione testes focados do parser e de Display para um e vários argumentos de string ordenados, preservando os argumentos da declaração como tipos de dados; considera-se concluído quando ambas as formas forem analisadas e convertidas de volta com sucesso.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
postgresql, rust
Domínio
compilers, databases
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Ativa
Clareza
Razoavelmente clara
Facilidade para iniciantes
52/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.