Skip to content
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

feature request: automatically quote columns #233

Open
momiji opened this issue Sep 11, 2023 · 1 comment
Open

feature request: automatically quote columns #233

momiji opened this issue Sep 11, 2023 · 1 comment

Comments

@momiji
Copy link

momiji commented Sep 11, 2023

Hello,

I've jsut discovered this great tool, which is incredible, except for this ugly ` quote character required when column names are not fully lowercased, which is really awful in our bash scripts...

I wonder if it was possible to have some sort of generic way of quoting columns, that can be automatically converted to the good column quote depending on the DB driver.

The idea is to allow something like SELECT [Id], [Name] FROM something and have it converted automatically to " or `.

Maybe the [...] is not the good solution, if some drivers support it, so we may want to switch to something else like {...} or |...|.
It should be something that can be used for all known DB drivers.

The complex thing is to parse the SQL string to detect what is inside strings and what is not, to perform the replacement only on the SQL part of the query.

What do you think?

@noborus
Copy link
Owner

noborus commented Sep 12, 2023

Thank you for the issue.

I would like to implement automatic rewriting if no other problems occur, but in reality unexpected problems do occur.
Therefore, I believe that it is best to pass the SQL statements written by the user as is.

In most cases, the database engine used by the user is known, and the user will write SQL statements appropriate for that database.

For example, SQLite3, which is used by many people, uses backquotes, so arguments are enclosed in single quotes and string literals are enclosed in double quotes.

trdsql -driver sqlite3 -ih -oh 'SELECT `Aaa`,`Bbb`,`Ccc`, "literal" as string FROM test.csv'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants