0

Here is what I would like to do:

declare maxNum integer;    
maxNum = select MAX(rn) from :ColumnList;

The sql statement returns a table with one row/col (one value).

Is there an easy way to assign this value to a scalar variable?

ThomasRones
  • 657
  • 8
  • 29

1 Answers1

3

The variable will be stored as an integer with this syntax.

declare maxNum integer;    
select MAX(rn) into maxNum from :ColumnList;

Edit: Thanks to Lars Br. for the explanation why this works.

ThomasRones
  • 657
  • 8
  • 29
  • 1
    The `SELECT INTO` form is plain SQL standard. nothing weird there. The idea is that a `SELECT` generates another table-like thing (another relation in relational algebra) and not just a line with somehow connected scalar values. In order to "extract" individual values out of a single row the `SELECT INTO` syntax exists. – Lars Br. Feb 18 '20 at 23:38