Create a variable in Vertica

ScottieB picture ScottieB · Jun 11, 2013 · Viewed 12.5k times · Source

I am transitioning from SQL Server to Vertica. Is there any comparable way to create a variable?

Usually I do something like:

Define @myVariable int
Set @myVariable = select MAX(Field1) from myTable

Answer

Guillaume picture Guillaume · Jun 11, 2013

I do not think Vertica allows variables, except if you are using vsql directly, but then vsql variables are very limited and will not do what you expect:

-- this will work
\set a foo
\echo :a
foo

-- this is not what you expect:
\set a NOW()
\echo :a
NOW()

\set a select max(id) from s.items()
\echo :a
selectmax(id)froms.items()

See for more information the vertica doc at https://my.vertica.com/docs/6.1.x/HTML/index.htm#2732.htm