Skip to content

Commit 990d5b3

Browse files
committed
docs: detail enum output and sample generation
1 parent 8deaa8f commit 990d5b3

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

AST_RESEARCH.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ Because PG16 introduced large changes, direct translation from PG13 to PG17 may
125125
| 16 | JsonAggConstructor, JsonArrayAgg, JsonArrayConstructor, JsonArrayQueryConstructor, JsonConstructorExpr, JsonFormat, JsonIsPredicate, JsonKeyValue, JsonObjectAgg, JsonObjectConstructor, JsonOutput, JsonReturning, JsonValueExpr, RTEPermissionInfo |
126126
| 17 | JsonArgument, JsonBehavior, JsonExpr, JsonFuncExpr, JsonParseExpr, JsonScalarExpr, JsonSerializeExpr, JsonTable, JsonTableColumn, JsonTablePath, JsonTablePathScan, JsonTablePathSpec, JsonTableSiblingJoin, MergeSupportFunc, SinglePartitionSpec, WindowFuncRunCondition |
127127

128+
## Generating AST Samples
129+
130+
To fully understand structural differences we will compile **libpg-query** for
131+
each supported PostgreSQL version and capture JSON output for a library of
132+
representative queries. This multi-runtime parser setup lets us record actual
133+
ASTs from PG13 through PG17. These samples are essential for training upgrade
134+
logic and verifying enum representations:
135+
136+
- PG13 and PG14 output enum values as integers
137+
- PG15+ output enums as their string names
138+
139+
The generated samples will live under a dedicated directory and can be compared
140+
programmatically to spot changes beyond what the protobuf types reveal.
141+
128142

129143
## Conclusion
130144

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ npm install @pgsql/enums
104104
- **Need fingerprint, normalize, or deparse?** → Use `@libpg-query/parser` (PG 17 only)
105105

106106

107+
### Enum Output Format
108+
109+
Earlier releases of `libpg_query` (PostgreSQL 13 and 14) emit **numeric** codes
110+
for enum fields in the parsed AST JSON. Starting with PG15 the JSON instead uses
111+
the **string name** of each enum value. When translating ASTs from older
112+
versions you must convert these integers to their corresponding strings.
113+
114+
107115
## API Documentation
108116

109117
For detailed API documentation and usage examples, see the package-specific READMEs:

parser/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ Each version export provides:
103103
- `parse(query)`: Parse a query (async)
104104
- `parseSync(query)`: Parse a query (sync, requires loadModule first)
105105

106+
### Enum Output Format
107+
108+
Parsing with PostgreSQL 13 and 14 returns enum fields as **integers** in the
109+
resulting AST JSON. From PG15 onward those fields contain the **string names** of
110+
the enum values. When upgrading ASTs across versions you may need to convert
111+
numeric enums from older parsers into strings.
112+
106113
## Credits
107114

108115
Built on the excellent work of several contributors:

0 commit comments

Comments
 (0)