Search code examples
sqlhadoophbaseapache-phoenix

Add a column to a table with a default value equal to the value of an existing column in HBase through Apache Phoenix


I have a table products with columns A, B.

I'd like to create a column C whose values are equal to B.

ALTER TABLE products ADD C DECIMAL(20,12);
UPDATE products SET C = B;

I'm getting some errors saying UPDATE statistics. Then I realised UPDATE is used for some other purpose. Then I tried it like below:

ALTER TABLE products ADD C DECIMAL(20,12);
ALTER TABLE products  SET C = B;

I got No rows affected and C is still null for all the rows. How to achieve this?


Solution

  • You can use this statements to create a column and update it based on value from another one:

    ALTER TABLE products ADD C DECIMAL(20,12);
    UPSERT INTO products(your_key, C) select your_key, B from products;