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

[VSCODE] SQLFlavourOverride: db2 .... Gets error on "#" character, even though db2 allows for it #550

Closed
moymike opened this issue Jan 21, 2023 · 4 comments
Labels
vscode Related to the VSCode Extension

Comments

@moymike
Copy link

moymike commented Jan 21, 2023

I'm working with DB2 (iSeries) SQL statements. One of the primary databases I work with includes "#" within the library name.

Example:
select * from db#prod.pohead where ponum = 1111;

Format Document error
Unable to format SQL: Error: Parse error: Unexpected "#prod.pohead" at line 99 column 99

If I use the IBM Client Access SQL tool, the format works fine. It appears that the the "Prettier-SQL.SQLFlavourOverride": "db2" is not allowing character "#" in the library name even though it is valid.

@moymike moymike added the vscode Related to the VSCode Extension label Jan 21, 2023
@moymike moymike changed the title [VSCODE] Issue Title Here [VSCODE] SQLFlavourOverride: db2 .... Gets error on "#" character, even though db2 allows for it Jan 21, 2023
@nene
Copy link
Collaborator

nene commented Jan 21, 2023

Thanks for reporting.

Could you provide a link to DB2 documentation that specifies which characters are allowed in database names?

I've been following this document, which only mentions:

An ordinary identifier is an uppercase letter followed by zero or more characters, each of which is an uppercase letter, a digit, or the underscore character.

Apparently that's not the full story, but I'm not familiar enough with DB2 to know from where to look for better sources.

@moymike
Copy link
Author

moymike commented Jan 22, 2023

In DB2 the database tables are stored as LIBRARY.FILE. (Lib.PF or Lib.LF) The naming of libraries (and library items) allow for A-Z, @, $, #, 0-9, underscores (_), and periods (.).

(oh... and just noticed ... the periods (.) character would NOT work for sql, but apparently it can be used in naming)

IBM i library naming rules

Although these special characters are allowed, and a lot of systems contain them, they can be problematic. This likely was not an issue years ago though, when many systems, such as ours was designed.

Db2 object naming rules

I tested another VScode extension "Sql Formatter" which has a "db2" option that works with the "#" library name.

If you update the extension please let me know and I'll try it out. Your extension contains more formatting options.

@nene
Copy link
Collaborator

nene commented Jan 22, 2023

Thanks for the references. I'll see what I can do to fix this.

I tested another VScode extension "Sql Formatter" which has a "db2" option that works with the "#" library name.

There seem to be many VSCode extensions named "SQL Formatter", all of them being wrappers around this same library, though often using an outdated version. The older versions of this library were more willing to treat all kinds of text as valid SQL.

@nene nene closed this as completed in c598126 Jan 22, 2023
@nene
Copy link
Collaborator

nene commented Jan 22, 2023

This issue should be fixed now in sql-formatter 12.0.6.

Not sure though when the fix will make it to the Prettier-SQL extension.

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

No branches or pull requests

2 participants