skip to Main Content

I have 2 columns of type int
and I want to make a concat to two columns in presto syntax. it is possible?
for example:

id:

  1. 345
  2. 997

age:

  1. 23
  2. 55

new_col:

  1. 34523

  2. 99755

I was trying to use the array function but it is not working :/

thanks to everyone!

2

Answers


  1. As presto can not convert automatically

    CONCAT(cast(id as varchar),cast(age as varchar))
    
    Login or Signup to reply.
  2. You concatenate strings.

    You calculate with integers.

    So, multiply one column by 100, and add the other. And the result is another integer, not a string.

    Data Types matter. And integers are way faster than strings.

    WITH
    -- your input, one table, don't use in final query ...
    id(id,idcol) AS (
                SELECT 1, 345
      UNION ALL SELECT 2, 997
    )
    ,
    -- your input, other table, don't use in final query ...
    age(id,agecol) AS (
                SELECT 1, 23
      UNION ALL SELECT 2, 55
    )
    -- real query starts here ...
    SELECT
      id.id
    , idcol * 100 + agecol AS new_col
    FROM id JOIN age USING(id)
    ORDER BY 1
    -- out  id | new_col 
    -- out ----+---------
    -- out   1 |   34523
    -- out   2 |   99755
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search