4 ms·
I'm surprised this doesn't mention the class of parsers I believe to be the most useful - the database in question itself. For example I make extensive use of h
by TkTech 4y ago
I'm surprised this doesn't mention the class of parsers I believe to be the most useful - the database in question itself. For example I make extensive use of https://pglast.readthedocs.io/en/v3/ https://pglast.readthedocs.io/en/v3/, which is the postgres SQL parser extracted into a standalone library (pg_query). No 3rd party library attempting to parse a particular flavour of SQL will be more accurate than the database that defines that flavour, since you're also getting all of the edge cases and quirks of it's impementation.
- mayoi 4y agoYeah this also seems very weird to me. Like, okay, that's cool, but did you ever hear of this thing called integration testing?
- valenterry 4y agoI think the article focuses on SQL parsing that builds an AST that's usable in the programming language of your choice to analyze/transform the AST. so you'd have to write a mapping at least. Otherwise I agree.
- thejosh 4y agoYep, it depends on what you want to do. Validating the SQL is correct is handy -- of course, but sometimes you need the AST.
- sanxiyn 4y agopg_query does return the AST.
- valenterry 4y agoHow do I pass my programming language as parameter to it?
- emaginniss 4y agoWhy would you need to pass in your language? The AST is data. You can then take that AST, which is already validated and disambiguated and act upon it in any way that you'd like.
- valenterry 4y agoBecause I want to analyze and transform the AST with the tools and libraries that my programming language offers. To be more precise, I want the data to be datatypes of my programming language and not JSON or some custom structure that I have to first parse myself.
- deleted 4y ago[deleted]
- jiggawatts 4y agoIn the same vein, I found this official library for parsing Microsoft T-SQL: https://devblogs.microsoft.com/azure-sql/programmatically-parsing-transact-sql-t-sql-with-the-scriptdom-parser/ https://devblogs.microsoft.com/azure-sql/programmatically-pa... I used it for a nasty global search & replace where a statement with quoted strings was sometimes embedded in quoted strings.
- hobs 4y agoIt's nice but it has a buuuuuuuunch of bugs - the published railroad diagrams/bnf grammar dont even match behavior in the wild so I feel bad for them, but you can see intellisense fail for similar reasons.
- pbowyer 4y agoAnyone know of the same for MySQL/MariaDB? I've found their grammar in the repository, but having a library would be better. I've found unofficial attempts but they have all mishandled parts of SQL compared to the built-in MySQL parser.
- password4321 4y agohttps://github.com/dolthub/go-mysql-server/blob/main/SUPPORTED.md#notable-limitations https://github.com/dolthub/go-mysql-server/blob/main/SUPPORT... is popular but not 100%
- pbowyer 4y agoBeen reporting many ~bugs~ spec inconsistencies there :) Apart from parser differences there's no support for SQL_MODE options yet.