-
Notifications
You must be signed in to change notification settings - Fork 605
Incorrect parsing literals that consisting of digits and letters, beginning with digits #804
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
Comments
Althrough nodody would name their columns like CREATE DATABASE test;
use test;
CREATE TABLE my_table (
id int,
1col int,
2col int
);
INSERT INTO my_table VALUES (1,2,3);
INSERT INTO my_table VALUES (2,3,4);
INSERT INTO my_table VALUES (3,4,5);
SELECT * FROM my_table;
SELECT 1col FROM my_table MariaDB [(none)]> CREATE DATABASE test;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> use test;
INSERT INTO my_table VALUES (3,4,5);
SELECT * FROM my_table;
SELECT 1col FROM my_table
Database changed
MariaDB [test]> CREATE TABLE my_table (
-> id int,
-> 1col int,
-> 2col int
-> );
Query OK, 0 rows affected (0.029 sec)
MariaDB [test]>
MariaDB [test]> INSERT INTO my_table VALUES (1,2,3);
Query OK, 1 row affected (0.005 sec)
MariaDB [test]> INSERT INTO my_table VALUES (2,3,4);
Query OK, 1 row affected (0.003 sec)
MariaDB [test]> INSERT INTO my_table VALUES (3,4,5);
Query OK, 1 row affected (0.007 sec)
MariaDB [test]>
MariaDB [test]> SELECT * FROM my_table;
+------+------+------+
| id | 1col | 2col |
+------+------+------+
| 1 | 2 | 3 |
| 2 | 3 | 4 |
| 3 | 4 | 5 |
+------+------+------+
3 rows in set (0.000 sec)
MariaDB [test]> SELECT 1col FROM my_table
-> ;
+------+
| 1col |
+------+
| 2 |
| 3 |
| 4 |
+------+
3 rows in set (0.000 sec)
MariaDB [test]>
|
I believe this is intended behaviour, at least for Generic/Postgres dialect. Relevant bit of discussion here: Though some dialects can support having their identifiers begin with a number, such as Hive: Though this does cause some issues with parsing numbers, for example exponent parsing does not work (related to above discussion) Since Hive supports it, same could be enabled for MySql now which has an existing comment about it: |
Any update about this issue? do this issue should be fixed in the near future for mysql? thanks. |
It seems when parsing a literal beginning with digits, the sql parser simply ends this token when meets a non-numeric character
see https://github.com/sqlparser-rs/sqlparser-rs/blob/main/src/tokenizer.rs#L547
For example,
123foobar
would be parsed into a number token123
and a word tokenfoobar
instead of one word token123foobar
.And
123foobar456
would be parsed into123
andfoobar456
The text was updated successfully, but these errors were encountered: