SQL dialect converter to YQL
The SQL dialect converter is a service that converts SQL queries written in other dialects (PostgreSQL, MySQL, ClickHouse, and others) into YQL syntax. The service is designed to simplify migration of existing queries to YDB and lower the entry barrier for developers already familiar with other DBMSs.
The converter is available as a standalone web application at ydb-dialect-converter.website.yandexcloud.net, and is also built into the DBeaver plugin for YDB and the VS Code plugin for YDB. The user pastes a query in the source dialect, selects the dialect from the list, and gets a version of the same query in YQL.
How to use
- Open the converter web interface.
- Select the source SQL dialect from the drop-down list.
- Paste the query into the Input SQL query field. If necessary, use the ready-made examples (
CTE Example,Create Table Example, and others). - Click Convert — the YQL result will appear in the Conversion result (YDB) field.
How it works
The conversion is performed in three stages:
- Parsing the source SQL. The source query is parsed by the specific dialect parser into an abstract syntax tree (AST) — a structure that describes the query's meaning independently of syntax.
- AST transformation. Constructs specific to the source dialect are replaced with their YQL equivalents. For example, type casting functions, date and string handling,
LIMIT/OFFSEToperators, andWITHconstructs are adapted to YQL rules. - YQL generation. A textual representation of the query in YQL is generated from the modified AST.
The stages are implemented using the SQLGlot library and the YDB plugin for it, which adds a separate YDB dialect to SQLGlot. SQLGlot is an open-source SQL parser and transpiler that supports over twenty dialects. It serves both as the parser for the source query and as the YQL generator.
If you need not a one-time conversion in the GUI but to embed the transformation into your own code or data processing pipeline, use the plugin directly — see the SQLGlot article.
Warning
The source query is sent to an external HTTPS service. Do not send queries containing confidential data (personal data, trade secrets, identifiers of real objects in production) to the converter.
Supported dialects
The list of source dialects is determined by the set supported by SQLGlot. Among the main ones:
- PostgreSQL
- MySQL
- ClickHouse
- Microsoft SQL Server (T-SQL)
- Oracle
- Snowflake
- BigQuery
- Presto / Trino
- Spark SQL / Databricks
- SQLite
The current full list of dialects can be obtained via the converter API or viewed in the SQLGlot source code. The target dialect is always YQL.
Supported constructs
The converter covers typical constructs of analytical and OLTP queries:
- SELECT operators:
SELECT,JOIN(all types),WHERE,GROUP BY,HAVING,ORDER BY,LIMIT,OFFSET. - Window functions (
OVER,PARTITION BY,ROWS BETWEEN). - Subqueries and CTE (
WITH). - Type casting (
CAST,::), arithmetic and logical operations. - Functions for strings, numbers, dates, and time — mapped to the nearest equivalent in YQL.
- Aggregate functions (
COUNT,SUM,AVG,MIN,MAX, and others). - DML operations:
INSERT,UPDATE,DELETE(taking into account transaction features of YDB).
Limitations
Full automatic conversion is not always possible, since YQL and other SQL dialects differ in data models and operation semantics. In particular:
- Dialect-specific functions. Functions that have no direct equivalent in YQL (for example, PostgreSQL arrays,
JSON_EXTRACTMySQL with special path syntax) are translated to approximate equivalents or left for manual refinement. - Stored procedures and triggers. Not supported, as YDB uses a different model for executing code in the database.
- Dialect-specific DDL.
CREATE TABLEfor complex types may require manual adjustment considering columnar and row-based tables in YDB. - Optimizer hints. Ignored: the YDB optimizer has its own control mechanisms.
The conversion result should be considered a draft: complex queries require manual review and adaptation before execution.