I am trying to replace the value of one of the columns in the SELECT result to 0. Normally I can do:
SELECT
0 AS column_to_set,
other_col_1,
other_col_2,
...
FROM tbl
However, there are lots of "other_cols" in the source table, and I wanted to avoid typing them all out.
Is there any way I can utilize SELECT *
but achieve the goal of replacing the value for one specific column? The engine is AWS Athena.
2
Answers
try to add alias on your table then do the alias.* on select
EX:
This is not supported in standard ANSI SQL as far as I know and this is not supported in Trino/Presto. And you can’t dynamically generate AND execute query (i.e. in one query) in Trino/Presto too (see this discussion @github).
The only "easy" option is to automate this by using
information_schema.columns
to generate the desired query. It can be done via a separate query (i.e. you write a query which will generate the desired one) or some "outside" scripting. For example imagine we havenation
table with columnsnationkey
,name
,regionkey
andcomment
with goal to replacecomment
. Then the following query:Will result in the following output: