Hi Steve,

You can do what you want with a view today, but the syntax is just a bit
different than what you tried. You declare your dynamic columns after the
view name, like this:

    create MY_VIEW("dynamic_field" varchar) as select * from MY_TABLE

You can also alter a view and dynamically add/remove columns on-the-fly.

    alter view MY_VIEW add "dynamic_field2" varchar;
    alter view MY_VIEW drop column "dynamic_field1";

You can even conditionally add a column only if it's not already there:

    alter view MY_VIEW add if not exists "dynamic_field2" varchar;

See full syntax here[1].

It's a cheap operation, as the only thing that's happening behind the
scenes is the update of the metadata. The advantage (as you've seen) is
that Phoenix is tracking all your dynamic columns.

Thanks,
James

[1] https://phoenix.apache.org/language/index.html#alter

On Thu, Feb 25, 2016 at 3:31 AM, anil gupta <[email protected]> wrote:

> +1 for a view that has dynamic columns. This would make life easier with
> dynamic columns.
>
> On Tue, Feb 23, 2016 at 4:00 PM, Steve Terrell <[email protected]>
> wrote:
>
>> I have a table with many dynamic fields.  Works great.  However, it's a
>> bit of a nuisance to have to supply each dynamic field's type in every
>> query.
>>
>> Example:
>> select "dynamic_field" from MY_TABLE("dynamic_field" varchar)
>>
>> This example is not too bad, but image it with 5+ dynamic fields being
>> used.  The select statement becomes very verbose.
>>
>> I understand the reason behind requiring the field type of each dynamic
>> field.  But I was wondering if there is a way to define a view that manages
>> the dynamic field types so that I could do something like this:
>>
>> create MY_VIEW as select * from MY_TABLE("dynamic_field" varchar)
>> -- invalid syntax; pseudo code of what I wish I could do.
>>
>> select "dynamic_field" from MY_VIEW
>>
>> Should I create a JIRA for a new feature?  Or is this fundamentally not
>> possible?
>>
>> Thanks,
>>     Steve
>>
>
>
>
> --
> Thanks & Regards,
> Anil Gupta
>

Reply via email to