简体   繁体   中英

SQLint showing a syntax error, yet batch file is run correctly?

I'm using Sublime Text with the SublimeLinter-contrib-sqlint plugin and following the tutorial examples at https://dev.mysql.com/doc/refman/8.0/en/examples.html , one of which contains the following:

CREATE TABLE shop (
    article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
    dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
    price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
    PRIMARY KEY(article, dealer));
INSERT INTO shop VALUES
    (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),
    (3,'C',1.69),(3,'D',1.25),(4,'D',19.95);

In Sublime Text with the linter enabled, I see a syntax error:

在此处输入图片说明

If I hover over it, it just says "ERROR: Syntax error near "("". However, it seems to run fine as batch input:

mysql> source shop.sql
Query OK, 0 rows affected (0.07 sec)

Query OK, 7 rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql> 

Any idea what might be causing this 'false positive' syntax error?

Your issue looks like it's caused by the underlying linting tool not using the correct dialect of SQL, which makes it think that the SQL you're using is not valid even though (for MySQL) it is.

Looking a bit deeper, the SublimeLinter-contrib-sqlint package says that it uses sqlint to do the linting, and the README in that repository includes this:

At this stage, SQLint checks SQL against the ANSI syntax, and uses the PostgreSQL SQL parser to achieve this. In time, we hope to add support for non-standard SQL variants (eg MySQL). Contributions are welcome.

As such it seems like at the moment the tool isn't capable of linting SQL files that use non-ANSI/PostgreSQL flavoured SQL.

我不认为字符串是INT的有效默认值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM