Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL with $ inside the column name are not parsed and formatted. #830

Closed
traycho opened this issue Feb 21, 2025 · 3 comments
Closed

SQL with $ inside the column name are not parsed and formatted. #830

traycho opened this issue Feb 21, 2025 · 3 comments
Labels

Comments

@traycho
Copy link

traycho commented Feb 21, 2025

Input data

Which SQL and options did you provide as input?

SELECT A.T$REFA orderId from TABLE_NAME;

Expected Output

SELECT  
   A.T$REFA orderId 
from 
TABLE_NAME;

Actual Output

Error: Parse error: Unexpected "$REFA orde" at line 1 column 11.
This likely happens because you're using the default "sql" dialect.
If possible, please select a more specific dialect (like sqlite, postgresql, etc).
    at TokenizerEngine.createParseError (TokenizerEngine.ts:61:12)
    at TokenizerEngine.tokenize (TokenizerEngine.ts:49:22)
    at Tokenizer.tokenize (Tokenizer.ts:26:65)
    at LexerAdapter.tokenize (createParser.ts:23:37)
    at LexerAdapter.reset (LexerAdapter.ts:18:24)
    at Parser.feed (nearley.js:281:15)
    at Object.parse (createParser.ts:33:34)
    at Formatter.parse (Formatter.ts:37:49)
    at Formatter.format (Formatter.ts:31:22)
    at formatDialect (sqlFormatter.ts:97:57)

Usage

  • How are you calling / using the library?
import { format as formatSQL } from "sql-formatter";
const sql = 'SELECT A.T$REFA orderId from TABLE_NAME;'
format(sql, { language: "sql" })

  • What SQL language(s) does this apply to?
    All of them I guess.

  • Which SQL Formatter version are you using?
    15.4.10

@traycho traycho added the bug label Feb 21, 2025
@traycho traycho changed the title [FORMATTING] Issue Title Here SQL with $ inside the column name are not parsed and formatted. Feb 21, 2025
@nene
Copy link
Collaborator

nene commented Feb 22, 2025

  • What SQL language(s) does this apply to?
    All of them I guess.

I'm sorry to inform you that your guess in incorrect. Only some SQL dialects support $ character inside identifiers.

The error message gives you a hint here:

Error: Parse error: Unexpected "$REFA orde" at line 1 column 11.
This likely happens because you're using the default "sql" dialect.

Use a specific dialect like:

format(sql, { language: "postgresql" })

And it will parse fine.

@nene nene closed this as completed Feb 22, 2025
@traycho
Copy link
Author

traycho commented Feb 22, 2025

Anyway i have solved it myself.

Sounds the SQL ANSII wants this to be quoted.

@nene
Copy link
Collaborator

nene commented Feb 22, 2025

FYI. For Oracle you can use:

format(sql, { language: "plsql" })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants