You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by Afshin Moazami <Af...@guavus.com> on 2015/12/21 21:42:16 UTC

How to create a view with case

I am trying to create a view on a table in Apache Phoenix and add/change the values of one of the base table columns in the view.

Something like this:

CREATE VIEW mobile_product_metrics (new_col varchar) AS
SELECT * ,
(CASE metric_type WHEN 'm' THEN 'mobile'
WHEN 'p' THEN 'phone'
ELSE 'unknown' END ) AS new_col
FROM product_metrics;


I am wondering if this is supported by Phoenix.

Re: How to create a view with case

Posted by James Taylor <ja...@apache.org>.
You'd need to create multiple views, one for each metric_type:

CREATE VIEW mobile_product_metrics (new_col1 varchar) AS SELECT * FROM
product_metrics WHERE metric_type = 'm';

CREATE VIEW phone_product_metrics (new_col2 varchar) AS SELECT * FROM
product_metrics WHERE metric_type = 'p';

On Monday, December 21, 2015, Afshin Moazami <Af...@guavus.com>
wrote:

> I am trying to create a view on a table in Apache Phoenix and add/change
> the values of one of the base table columns in the view.
>
> Something like this:
>
> CREATE VIEW mobile_product_metrics (new_col varchar) AS
> SELECT * ,
> (CASE metric_type WHEN 'm' THEN 'mobile'
> WHEN 'p' THEN 'phone'
> ELSE 'unknown' END ) AS new_col
> FROM product_metrics;
>
> I am wondering if this is supported by Phoenix.
>