You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As we can see, NVL does NOT care about the type, COALESCE does. Therefore both function are not identical.
In python with sqlglot:
sqlQuery: str = """ SELECT * FROM TEST1 WHERE NVL(COL2, 1) <> COL1"""
sql = sqlglot.parse_one(sql=sqlQuery, read='oracle')
print(sql.sql(dialect='oracle'))
-> SELECT * FROM TEST1 WHERE COALESCE(COL2, 1) <> COL1
I should have NVL and not COALESCE. These 2 functions are not identical.
Official Documentation
Please include links to official SQL documentation related to your issue.
Fully reproducible code snippet
In oracle DB :
--> COL1 COL2
1 2
--> ORA-00932: inconsistent datatypes: expected : CHAR ; got : NUMBER
As we can see, NVL does NOT care about the type, COALESCE does. Therefore both function are not identical.
In python with sqlglot:
sqlQuery: str = """ SELECT * FROM TEST1 WHERE NVL(COL2, 1) <> COL1"""
sql = sqlglot.parse_one(sql=sqlQuery, read='oracle')
print(sql.sql(dialect='oracle'))
-> SELECT * FROM TEST1 WHERE COALESCE(COL2, 1) <> COL1
I should have NVL and not COALESCE. These 2 functions are not identical.
Official Documentation
Please include links to official SQL documentation related to your issue.
https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/NVL.html
"If expr1 is character data, then Oracle Database converts expr2 to the data type of expr1 before comparing them and returns VARCHAR2 in the character set of expr1."
The text was updated successfully, but these errors were encountered: