antares-sql / antares

A modern, fast and productivity driven SQL client with a focus in UX
https://antares-sql.app
MIT License
1.6k stars 111 forks source link

Table names in column list are extraneous/incorrect for "Copy as SQL insert" #822

Open bart-schaefer opened 4 days ago

bart-schaefer commented 4 days ago

When performing "Copy > Row (SQL INSERT)" (or "Rows (SQL INSERT)"), the resulting SQL has table names in the column list. Example, a query like this:

select domain_name, version, cast(public_key as char) as public_key, cast(private_key as char) as private_key, update_time, published_time from domain_key where domain_name in (...)

Creates INSERT statments like this:

INSERT INTO `domain_key` (`domain_key.domain_name`, `domain_key.version`, `.public_key`, `.private_key`, `domain_key.update_time`, `domain_key.published_time`) VALUES (...)

Note that the cast(...) selections generate column names with a leading dot but no table name, and the table name is at least unnecessary in the other columns in the list as well.

Expected behavior Generate just the column names without table name tagging.

INSERT INTO domain_key (domain_name, version, public_key, private_key, update_time, published_time) VALUES (...)

In the case where an expression like cast(...) or ifnull(...) etc. appears in the select list without an AS name, MySQL CLI reproduces that entire expression in backticks, which may or may not match a column name in the target table -- but that at least can be handled by properly using AS. In the current output, every INSERT statement must be edited after copy/paste to remove the table names.

Antares version 0.7.23 MacOS connecting to MySQL 8.0.35 or 5.7.44