taozhi8833998 / taozhi8833998/node-sql-parser

Add Support for TRY_CAST in PostgreSQL Dialect

Open
#2,142 0 comments 5 reactions 1 assignee View on GitHub

@taozhi8833998 is already working on this.

Since Sep 27, 2024.

Dominant language
PEG.js
Stars
1k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
We are using the PostgreSQL dialect to verify SQL queries. Along with that, we support various SQL functions, and one of the functions we use is TRY_CAST. However, PostgreSQL dialect natively supports CAST but does not support TRY_CAST.

We need a way to add support for the TRY_CAST function, even though PostgreSQL itself does not have native support for this function.

Database Engine
PostgreSQL + Additional Custom Function

To Reproduce
-the SQL that be parsed: select TRY_CAST(field1 as INT) from table
-the node-sql-parser version: 5.2.0
Node Version: 20+

Expected behavior
TRY_CAST should function similarly to other databases that support it, where it tries to cast the value to the target type and returns NULL if the cast fails.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.