How to create a computed / derived column

Moderator: NorbertKrupa

Post Reply
mohamed_ezz
Newbie
Newbie
Posts: 6
Joined: Wed Jan 09, 2013 9:55 pm

How to create a computed / derived column

Post by mohamed_ezz » Mon May 27, 2013 6:29 pm

Hi,

I need to create a derived column like in SQL Server http://msdn.microsoft.com/en-us/library ... .105).aspx

A computed column is not physically stored on disk, but rather computed each time it is queried. What I really want from this functionality is that I can change the expression by which this column is computed and get the same effect as if I updated this column for all the rows. Example :

Code: Select all

create table comp(a INT, b INT, result float AS b/a); (<< this syntax doesn't work on vertica 6.0)
insert into comp values(4,8)
select * from comp;
a   |    b    |   result
==================
4        8            2

when I change the equation b/a by something else like b+2*a for example...then i query the table again, I should see :

Code: Select all

select * from comp;
a   |    b    |   result
==================
4        8            16
without having to explicitly UPDATE the table. This is because each time I query the table, the function of the computed column is applied.

How can I do this in Vertica ?
(I know there's an option to specify the DEFAULT value as an equation/expression, but this doesn't give the effect I want, because the column is physically stored.)

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: How to create a computed / derived column

Post by id10t » Mon May 27, 2013 7:06 pm

Hi!

If don't want store physically so only - VIEW ...

Post Reply

Return to “Vertica SQL”