SELECT -col1, -col14 FROM table LIMIT 50;
Where the minus sign means I don't want these two columns. I still don't see a way to do it easily (for Vertica and in Datagrip).
SELECT -col1, -col14 FROM table LIMIT 50;
Where the minus sign means I don't want these two columns. I still don't see a way to do it easily (for Vertica and in Datagrip).
- BQ https://cloud.google.com/bigquery/docs/reference/standard-sq...
- CH https://clickhouse.com/docs/en/sql-reference/statements/sele...
GROUP BY every column except for <these>
It feels silly when you are SELECTing a ton of columns, then you add a JOIN to a many-to-one relationship which you want to aggregate. Now you need to either make it a subquery (and hope the optimizer doesn't screw up) or duplicate all your SELECT expression (not even the identifiers) into the GROUP BY. select division_name, branch_name, dealer_id, dealer_name, quarter, month, sum(total_paid)
from divsions, branches, dealers, transactions
where ..... --buncha joins
group by division_name, branch_name, dealer_id, dealer_name, quarter, month
If I didn't want to group the result by division_name, branch_name, dealer_id, dealer_name, quarter and month, why would I put them in the select clause? SELECT t.i+1, count(*) FROM table t GROUP BY 1
1 in this context means the first selected item (i.e. t.i+1). I know this works in PostgreSQL.SQL has always been that language that is easy to read. even when you don't understand what the queries are doing. adding a cryptic syntax like "-column" would make it less readable.
EXCEPT is already a keyword and has is used for set-based operations, so I don't think it's good to overload it.
This is already valid SQL. Example: SELECT -col1, -col4 FROM (SELECT 1 AS col1, 2 AS col4) AS tbl;
Do you think seriously that a new meaning could ever be attached to that syntax?
I’ve done it for many years (using named columns/ dictionaries as the result set) and its never been an issue.
Things such as SELECT * EXCEPT col1, col2 are really a PIA to write and can build up frustration level really quickly. Certain IDEs such as Datagrip ease the process by providing "macros" but they are not enough.
Another thing is to generate useful boilerplates such as SELECT col1 FROM table GROUP BY col1 ORDER BY col1 to explore all unique values of col1.
dt[1:50, -c('col1', 'col14')]