Skip to content

Incorrect Transpilation of PostgreSQL Concatenation Operator || to MySQL #43

@drawmoon

Description

@drawmoon

Description
When transpiling a SQL query from PostgreSQL dialect to MySQL dialect using polyglot_sql.transpile, the string concatenation operator || is incorrectly converted to the logical OR operator. This leads to semantically incorrect SQL.

Reproducible Example
Below is a Python code snippet that demonstrates the issue. The expected output for MySQL should use the CONCAT function, but polyglot-sql produces OR instead.

import polyglot_sql
polyglot_sql.transpile("SELECT 'A' || 'B'", read="postgres", write="mysql") # ["SELECT 'A' OR 'B'"]

# And generate
ast = polyglot_sql.parse_one("SELECT 'A' || 'B'", dialect="postgres")
polyglot_sql.generate(ast, dialect="mysql") # ["SELECT 'A' || 'B'"]

Expected Behavior
The correct transpilation from PostgreSQL's || (string concatenation) to MySQL should result in the use of the CONCAT() function.

Comparison with sqlglot

import sqlglot
sqlglot.transpile("SELECT 'A' || 'B'", read="postgres", write="mysql") # ["SELECT CONCAT('A', 'B')"]

Suggested Fix
Ensure that the PostgreSQL string concatenation operator || is correctly mapped to MySQL's CONCAT() function during transpilation within polyglot-sql.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions