Packages icon indicating copy to clipboard operation
Packages copied to clipboard

[SQL] `#` marking temporary table instead starts a comment

Open aidas-atu opened this issue 11 months ago • 5 comments

Description of the bug

Normally temp tables in SQL starts # character, and everything after becomes highligted as a comment.

Steps to reproduce

paste these into sublime when highlighting is set to SQL:

select * from #table where id = 2
select * from table1 where id = 2

1st line after # is highlighted as comment

Expected behavior

# character should not be treated as a start of a commnet.

Actual behavior

# character is treated as a start of a comment.

Sublime Text build number

4189

Operating system & version

Windows 11 pro

aidas-atu avatar Jan 06 '25 09:01 aidas-atu

Which server?

Current SQL syntax primarily supports MySQL, which says the following about comments and identifiers:

  • https://dev.mysql.com/doc/refman/8.0/en/comments.html
  • https://dev.mysql.com/doc/refman/8.0/en/identifiers.html

According to those specs, # introduces a line comment and unquoted identifiers may consist of ASCII only.

Same is true for MariaDB

  • https://mariadb.com/kb/en/comment-syntax/
  • https://mariadb.com/kb/en/identifier-names/

deathaxe avatar Jan 06 '25 11:01 deathaxe

Looks like MS SQL Server. Maybe explain DefaultSyntaxChooser?

michaelblyons avatar Jan 06 '25 15:01 michaelblyons

Can confirm, T-SQL syntax supports hashed identifiers.

It is however not released with any ST build, so I assume the report targeting old naive implementation.

Anyway, maybe we should considder adding a simplified default syntax chooser so modifying default dialect works out of the box.

deathaxe avatar Jan 06 '25 17:01 deathaxe

@aidas-atu There is a pre-release version of syntax highlighting that fixes your issue. SQL has been broken into multiple flavors that have conflicting syntax specs. In this particular case, I think MySQL wants it to be a comment and MS SQL wants it to be a temp table.

If you want to use this feature before it releases, you can follow the instructions in the ReadMe of this repo, and then use the T-SQL flavor for your standalone SQL files. To get it embedded into strings in other languages, there are some more steps. Reply if those are needed.

michaelblyons avatar Jan 07 '25 16:01 michaelblyons

Note SQL is extended by and embedded in various syntaxes, thus various packages may need to be overridden to avoid errors with regards to "mismatching syntax versions".

deathaxe avatar Jan 07 '25 17:01 deathaxe

ST4200 is out with rewritten SQL supporting MSSQL / T-SQL.

Default SQL syntax used in embedded strings can be adjusted via DefaultSyntaxChooser until we come op with a bundled plugin providing suitable command for it.

deathaxe avatar May 21 '25 19:05 deathaxe