Comments (6)
I'm closing this, as there isn't much I can do, other that inventing that other layer, a big effort with uncertain advantage.
from pglast.
Out of curiosity, can you show a sample statement that exhibits the problem?
In general, though, I'd prefer to avoid fiddling with parser's output... but let's see.
from pglast.
Sure, no problem:
- Example where
rexpr
is adict
:
SELECT count(*) FROM head WHERE age > 56
[
{
"RawStmt": {
"stmt": {
"SelectStmt": {
"targetList": [
{
"ResTarget": {
"val": {
"FuncCall": {
"funcname": [
{
"String": {
"str": "count"
}
}
],
"agg_star": true,
"location": 7
}
},
"location": 7
}
}
],
"fromClause": [
{
"RangeVar": {
"relname": "head",
"inh": true,
"relpersistence": "p",
"location": 21
}
}
],
"whereClause": {
"A_Expr": {
"kind": 0,
"name": [
{
"String": {
"str": ">"
}
}
],
"lexpr": {
"ColumnRef": {
"fields": [
{
"String": {
"str": "age"
}
}
],
"location": 32
}
},
"rexpr": {
"A_Const": {
"val": {
"Integer": {
"ival": 56
}
},
"location": 40
}
},
"location": 37
}
},
"op": 0
}
}
}
}
]
- Example where
rexpr
is alist
:
SELECT avg(num_employees) FROM department WHERE ranking BETWEEN 10 AND 15
[
{
"RawStmt": {
"stmt": {
"SelectStmt": {
"targetList": [
{
"ResTarget": {
"val": {
"FuncCall": {
"funcname": [
{
"String": {
"str": "avg"
}
}
],
"args": [
{
"ColumnRef": {
"fields": [
{
"String": {
"str": "num_employees"
}
}
],
"location": 11
}
}
],
"location": 7
}
},
"location": 7
}
}
],
"fromClause": [
{
"RangeVar": {
"relname": "department",
"inh": true,
"relpersistence": "p",
"location": 31
}
}
],
"whereClause": {
"A_Expr": {
"kind": 11,
"name": [
{
"String": {
"str": "BETWEEN"
}
}
],
"lexpr": {
"ColumnRef": {
"fields": [
{
"String": {
"str": "ranking"
}
}
],
"location": 48
}
},
"rexpr": [
{
"A_Const": {
"val": {
"Integer": {
"ival": 10
}
},
"location": 64
}
},
{
"A_Const": {
"val": {
"Integer": {
"ival": 15
}
},
"location": 71
}
}
],
"location": 56
}
},
"op": 0
}
}
}
}
]
I'd prefer to avoid fiddling with parser's output
In general, I would agree. 👍
from pglast.
In the pglast code, this is solved by case matching the kind: https://github.com/aiham/pglast/blob/master/pglast/printers/dml.py#L120
from pglast.
Thank you, I see. And what do you do on that? I mean, what would be your ideal way to deal with the polymorphic nature of that "value"?
The problem is that the "knowledge" of the "concrete shape" of the value must be obviously coded somewhere... one idea (without much thinking, really!) would be having a way to implement an higher level AST, that is, using a machinery similar to the "printers" that instead of a serialized, textual representation of the "low level" syntax would produce more usable/generic nodes...
from pglast.
one idea (without much thinking, really!) would be having a way to implement an higher level AST
I think this is possible, but would require converting the A_Expr constructor into an A_Expr ADT with a set of constructors, one for each A_Expr kind. For instance:
A_Expr = A_Expr_Op(Val* name, Expr lexpr, Expr? rexpr)
| A_Expr_Between(Val* name, Expr lexpr, Expr rexpr1, Expr rexpr2)
| ...
something like that, where Type*
means multiple cardinality, Type?
means optional cardinality, and Type
means single cardinality.
from pglast.
Related Issues (20)
- Extra parens when formatting different operations HOT 2
- Support PG 15 HOT 5
- deparse_protobuf() broken on big-endian HOT 9
- Deparsing of modified queries and query parts HOT 3
- Double Quotes NOT preserved after parsing HOT 2
- Support statement types similar to referenced relations HOT 3
- Failed to install with pip (python 3.10.11) HOT 1
- ParseError when handling a statement containing a UUID HOT 1
- Token's reported location shifts when query has Turkish characters HOT 6
- Safety belt triggered HOT 2
- Duplicate `DEFERRABLE INITIALLY DEFERRED` in output HOT 3
- Can't compile with glibc >= 2.38 HOT 2
- pgpp remove important parentheses HOT 3
- Support PG16 HOT 6
- TypeError while init RawStmt from query parse tree dict which has A_Star. HOT 2
- (32-bit) FETCH ALL -> FETCH 2147483647 HOT 3
- Printing of AlterOwnerStmt for operator class results in error. HOT 3
- pglast>-6 install from wheel is missing symbol HOT 11
- referenced_relations: incorrectly treating LATERAL-ly-joined aliases as real relations HOT 4
- Question about the traverse method on v6 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pglast.