apache / apache/datafusion-sqlparser-rs

PostgreSQL 18 generated virtual columns require STORED

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

描述

## Summary

`PostgreSqlDialect` rejects PostgreSQL 18 generated columns when the generated-column mode is omitted.

PostgreSQL 18 supports both stored and virtual generated columns. Per the PostgreSQL 18 docs, generated columns are virtual by default and `VIRTUAL` / `STORED` are optional explicit mode keywords:

https://www.postgresql.org/docs/current/ddl-generated-columns.html

## Reproduction

Using `sqlparser` 0.62.0 with `PostgreSqlDialect`, parse:

```sql
CREATE TABLE users (
first_name text NOT NULL,
last_name text NOT NULL,
name character varying(255)
GENERATED ALWAYS AS (((first_name || ' '::text) || last_name))
NOT NULL
);
```

## Expected behavior

The statement parses successfully, with `name` represented as a generated virtual column. Since PostgreSQL 18 defaults generated columns to virtual, omitted mode should be accepted as virtual or at least accepted with no explicit mode.

## Actual behavior

Parsing fails with:

```text
sql parser error: Expected: STORED, found: NOT
```

This also affects PostgreSQL 18 `pg_dump` output, which emits generated virtual columns without an explicit `VIRTUAL` keyword, for example:

```sql
name character varying(255) GENERATED ALWAYS AS (((first_name || ' '::text) || last_name)) NOT NULL
```

## Notes

`GenericDialect` can parse a variant when `VIRTUAL` is made explicit, but `PostgreSqlDialect` currently appears to require `STORED` after `GENERATED ALWAYS AS (...)`.

贡献指南

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

调研方向

Start at the PostgreSqlDialect handling for generated columns and reproduce the supplied CREATE TABLE statement with an omitted mode. Ensure PostgreSQL 18 virtual generated columns are accepted, then add or run regression coverage showing that the statement parses successfully without requiring STORED.

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

评估

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

把新 issue 发到你的邮箱

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