interpost interpost - 3 months ago 10
SQL Question

Combining multiple SELECT INTO results into one variable

The method I am using may not be efficient (or possible), if so please let me know.
I am trying to use

SELECT INTO
to select two values and then attach them to a variable (v1) which will be returned by the function as one cell. Inserting
UNION ALL
between the two
SELECT INTO
statements results in an
ERROR: syntax error at or near "UNION"


EDIT - the function provides two unique values (not null) which are specified for these two SELECT INTO statements

desired output:

v1 v2 v3 etc.
2678, 2987


excerpt from function:

SELECT value
INTO v1
FROM table
WHERE year <= parameteryear;

SELECT value
INTO v1
FROM table
WHERE yearinteger >= parameteryear;

data := v1;
RETURN NEXT;
END;
$$ LANGUAGE plpgsql;

Answer
 SELECT cast(t1.value as varchar(20)) || ', ' || cast(t2.value as varchar(20))
     INTO v1
     FROM table as t1, table as t2
     WHERE t1.year <= parameteryear
       AND t2.yearinteger >= parameteryear;