Rejo Chandran
Rejo Chandran

Reputation: 609

Using variable name the same as column name - Clickhouse

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


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?

Upvotes: 1

Views: 1935

Answers (2)

Denny Crane
Denny Crane

Reputation: 13310

SELECT
    * REPLACE addMinutes(mydate, 300) AS mydate, mytable.mydate
FROM mytable

Upvotes: 1

Rich Raposa
Rich Raposa

Reputation: 808

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; 

Upvotes: 0

Related Questions