Comments (5)
You can see what's happening by looking at pgpp -t
output for the two statements, and spotting the difference: this is basically what the safety belt does, ie it compares the AST of the input statement with that of the prettified one, and if there is any discrepancy, it raises an exception.
A quick test revealed that, when there is a semicolon, the underlying PG parser emits a stmt_len
slot, not present otherwise:
$ diff -u <(echo "select * from i" | pgpp -t) <(echo "select * from i;" | pgpp -t)
--- /dev/fd/63 2018-03-25 10:51:54.356248860 +0200
+++ /dev/fd/62 2018-03-25 10:51:54.356248860 +0200
@@ -32,7 +32,8 @@
}
]
}
- }
+ },
+ "stmt_len": 15
}
}
]
I'll try to understand the meaning of that stmt_len
: AFAICT, it should be ignored when comparing the ASTs.
Thank you for reporting the issue!
from pglast.
Here there is a brief explanation of the meaning of stmt_len
.
Also libpg_query
seems to explicitly ignore it to compute statement's fingerprint.
So yes, I think it's just a matter of removing it from the structure before comparison, as we already do for the location field.
from pglast.
@lelit Just in case it helps, here is the full reference for the fingerprinting logic in pg_query itself: https://github.com/lfittl/libpg_query/wiki/Fingerprinting#version-20-based-on-postgresql-10
(the stmt_len is a Postgres 10 addition, and if I understand right I would ignore it for any comparisons between ASTs in your library as well)
from pglast.
Thanks Lukas for the confirmation!
from pglast.
I just release version 0.25 that fixes this.
from pglast.
Related Issues (20)
- Visualization HOT 3
- Tag a release? HOT 2
- Improve SubLink printer
- Improved(?) referenced_relations function HOT 17
- Using visitors you cannot replace elements from a list of values. HOT 5
- 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
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.