apache / apache/datafusion-sqlparser-rs

PostgreSQL 18 generated virtual columns require STORED

Abierto Apto para principiantes
#2,407 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
3.5k
Forks
772
Merge medio
4 d 9 h
PR fusionados (30 d)
17

Descripción

## 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 (...)`.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
postgresql, rust
Área
databases
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
73/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.