Giter VIP home page Giter VIP logo

Comments (5)

lelit avatar lelit commented on June 12, 2024

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.

lelit avatar lelit commented on June 12, 2024

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.

lfittl avatar lfittl commented on June 12, 2024

@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.

lelit avatar lelit commented on June 12, 2024

Thanks Lukas for the confirmation!

from pglast.

lelit avatar lelit commented on June 12, 2024

I just release version 0.25 that fixes this.

from pglast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.