英文:
Using variable name the same as column name - Clickhouse
问题
我有一个名为mytable的表,其中mydate是其中的一列。
然而,由于SELECT子句是动态的,我需要使用addMinutes预调整列。
因此,使用该函数将列添加到变量中,以便在列出现在SELECT中时,变量的值覆盖表中的实际值。
SELECT mydate FROM "mytable"
返回
mydate的原始值
WITH addMinutes(mydate, 300) AS mydate SELECT mydate FROM "mytable"
返回
mydate的原始值,预期返回变量值
恰好相反发生了;即使变量被提及(与列的名称相同),实际列值也会覆盖WITH子句。
我们是否有一种方法可以使用WITH子句中与表中列名称相同的变量?
英文:
I have a table mytable and mydate is a column in it.
However, since the SELECT clause is dynamic, I need to pre-adjust the column with addMinutes.
So, the column is added to the variable with the function such that in the event the column turns up in SELECT the variable is taken over than the actual value in the table.
SELECT mydate FROM "mytable"
> original value of mydate is returned
<br/>
WITH addMinutes(mydate,300) AS mydate SELECT mydate FROM "mytable"
> original value of mydate is returned, expected to return variable value
The exact opposite happens; Even if the variable is mentioned (same name as the column), the actual column value overrides the WITH clause.
Do we have a workaround to use WITH clause variables with the same name as the columns in the table?
答案1
得分: 1
SELECT
* REPLACE addMinutes(mydate, 300) AS mydate, mytable.mydate
FROM mytable
英文:
SELECT
* REPLACE addMinutes(mydate, 300) AS mydate, mytable.mydate
FROM mytable
答案2
得分: 0
I'm not aware of any workaround. The real question is: Why do you need the WITH clause to use the same variable name?
Everything works as expected if you use a different name:
WITH
addMinutes(mydate, 300) AS mynewdate
SELECT
mynewdate,
mydate
FROM mytable;
英文:
I'm not aware of any workaround. The real question is: Why do you need the WITH clause to use the same variable name?
Everything works as expected if you use a different name:
WITH
addMinutes(mydate, 300) AS mynewdate
SELECT
mynewdate,
mydate
FROM mytable;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论