TablePlus / TableTool-issue-tracker

1 stars 0 forks source link

Table name unclear for SQL queries #3

Closed jschuur closed 2 weeks ago

jschuur commented 3 weeks ago

I couldn't figure out how to reference the table for SQL queries. It's using DuckDB, so even something like SELECT * FROM read_csv("table.csv").

Is this supported yet?

huyphams commented 3 weeks ago

After you import the CSV, you can treat it just like a table. For example:

SELECT * FROM "table.csv";

jschuur commented 3 weeks ago

After you import the CSV, you can treat it just like a table. For example:

SELECT * FROM "table.csv";

Great, that worked, thanks!

Would be nice if that auto completed like in TablePlus. Or, even better there was an alias (source? file?) that I can use regardless of the actual file name. In my case the filename was quite long with a timestamp and other meta data in it.

Then I can just to SELECT count(*) FROM source e.g.

hamidafghan commented 2 weeks ago

You're able to rename the file after importing and querying the renamed (short name) file.

huyphams commented 2 weeks ago

Yep, you can rename it right there.

Screenshot 2024-06-12 at 5 39 19 PM
jschuur commented 2 weeks ago

Yep, you can rename it right there.

Very cool, but definitely not something I would have discovered without this thread. Thanks for pointing this out!

FWIW, I had to SELECT count(*) FROM "table" since SELECT count(*) FROM table without the quotes didn't work.

huyphams commented 2 weeks ago

FWIW, I had to SELECT count() FROM "table" since SELECT count() FROM table without the quotes didn't work.

I think it is related to the SQL syntax. If there is a dot, dash, space, mixed upper case-lowercase, new lines or some special character... in the table name, you need to add quotes.