dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.32k stars 656 forks source link

sql-insert formatter sometimes calls tables `DUAL` if the table name is not enclosed in back-ticks #1066

Open cricalix opened 1 year ago

cricalix commented 1 year ago

Context

Queries written without back-ticks on the table names will sometimes result in a table name of DUAL in the generated sql-insert formatted text.

mysql 10.5.15-MariaDB-0+deb11u1
mycli 1.23.2

cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"

To rule out debian packaging, I ran pip install -U mycli, which installed 1.25.0 and executed ~/.local/bin/mycli. The behaviour persisted.

Reproduction

The behaviour appears to be tied to table names, and the use (or lack thereof) of back-ticks when writing the query. I presume this is reserved keyword business of some sort, though the query executes just fine so I don't think it's a DB engine problem.

mysql root@(none):bar> \T sql-insert
Changed table format to sql-insert
Time: 0.000s

mysql root@(none):bar> create table alias (a int);
Query OK, 0 rows affected
Time: 0.027s

Query without back-ticks on table name

mysql root@(none):bar> select * from alias;
INSERT INTO `DUAL` (`a`) VALUES
;
0 rows in set

Query with back-ticks on table name

mysql root@(none):bar> select * from `alias`;
INSERT INTO `alias` (`a`) VALUES
;
0 rows in set
Time: 0.002s

So far I can get it to do this for the names

All these names are table names created by Postfixadmin..

I note that mycli syntax-highlights admin in the same colour as SELECT/FROM/LIMIT, but the other three do not get the same colour applied.