Working with Different Databases¶
This tutorial explores General SQL Parser .NET's support for the 15 built-in dialects and how to handle vendor-specific SQL.
Objectives¶
- Configure GSP for each of the 15 supported vendors
- Handle vendor-specific SQL features and extensions
- Parse Oracle PL/SQL blocks
- Work with SQL Server T-SQL specifics
- Manage PostgreSQL and MySQL syntax differences
- Switch dialect context effectively
Prerequisites¶
- Completed Basic SQL Parsing
- Familiarity with SQL differences across database systems
Time required¶
About 60 minutes.
Supported vendors¶
The .NET library ships with 15 dialects baked into the prebuilt NuGet package. Each maps to a member of the EDbVendor enum:
| Vendor | Constant | Notes |
|---|---|---|
| IBM DB2 | EDbVendor.dbvdb2 |
DB2 LUW + iSeries |
| Greenplum | EDbVendor.dbvgreenplum |
PostgreSQL fork |
| Apache Hive | EDbVendor.dbvhive |
HiveQL |
| Apache Impala | EDbVendor.dbvimpala |
Impala SQL |
| IBM Informix | EDbVendor.dbvinformix |
|
| MDX | EDbVendor.dbvmdx |
OLAP |
| Microsoft SQL Server | EDbVendor.dbvmssql |
Alias dbvaccess for MS Access |
| MySQL | EDbVendor.dbvmysql |
Plus MariaDB |
| IBM Netezza | EDbVendor.dbvnetezza |
|
| Oracle | EDbVendor.dbvoracle |
Includes PL/SQL |
| PostgreSQL | EDbVendor.dbvpostgresql |
|
| Amazon Redshift | EDbVendor.dbvredshift |
PostgreSQL-derived |
| Snowflake | EDbVendor.dbvsnowflake |
|
| Sybase ASE | EDbVendor.dbvsybase |
T-SQL family |
| Teradata | EDbVendor.dbvteradata |
Includes BTEQ + SPL |
If you build the library from source you can drop unused dialects with /p:includeXxx=false flags.
Step-by-step guide¶
1. Switching vendors¶
The vendor is selected at construction time and embedded in the parser:
1 2 3 4 5 6 7 8 9 10 11 12 | |
You cannot change vendor on an existing TGSqlParser. To analyse the same SQL against multiple dialects, construct one parser per vendor.
2. Oracle PL/SQL¶
Oracle is the only built-in vendor with a separate PL/SQL parser. TGSqlParser instantiates it automatically when it sees a BEGIN ... END; block, a CREATE PROCEDURE/FUNCTION/PACKAGE, or an anonymous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
See Parse Oracle PL/SQL for the deep dive.
3. SQL Server T-SQL¶
The MSSQL vendor handles full T-SQL — variables, control-of-flow, OUTPUT clauses, MERGE, CTEs, OPENJSON, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Sybase ASE shares a lot of grammar with MSSQL — use EDbVendor.dbvsybase for ASE-specific syntax (raiserror, sp_* extensions).
4. PostgreSQL & Greenplum & Redshift¶
PostgreSQL, Greenplum and Redshift share grammar ancestry. If your SQL targets a fork, pick the matching vendor — they recognise different reserved-word sets and dialect extensions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
5. MySQL specifics¶
1 2 3 4 5 6 7 8 9 | |
6. Snowflake¶
1 2 3 4 5 6 7 8 | |
7. Teradata¶
Teradata has its own SPL (stored procedure language) and BTEQ commands; both are handled.
1 2 3 4 5 6 7 8 9 10 | |
Building a vendor auto-detector¶
When you don't know the dialect ahead of time, try each vendor and pick the one that parses cleanly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
This is intentionally a sketch — for real workloads, weight the candidates by the actual mix of SQL you expect to see, and remember that simple SELECTs parse identically across most vendors so a "first match" wins.
Summary¶
You learned how to:
- Pick the right
EDbVendorfor each dialect - Parse Oracle PL/SQL blocks via the same
TGSqlParserentry point - Handle SQL Server T-SQL constructs (MERGE, OUTPUT, variables)
- Distinguish between PostgreSQL, Greenplum, and Redshift
- Recognise MySQL- and Snowflake-specific syntax
- Build a simple vendor auto-detector
What's next?¶
- Advanced Features — AST modification, custom visitors, performance
- Vendor-specific how-to guides: