-1

I have this function:

DECLARE 
    _first_name text;
    _last_name  text;
BEGIN
SELECT 
    emp.first_name INTO _first_name,
    emp.last_name INTO _last_name,
FROM employee emp LIMIT 1
END;

(I simplified the function to eliminate the information noise)

As you can see, i can get only 1 result because of 'LIMIT'. So i need to store this 2 columns into my 2 variables. But i am getting an error like 'INTO specified more than once'. How to bypass this, any ideas?

john2994
  • 393
  • 1
  • 3
  • 15
  • `INTO` is a clause and used once with multiple variables. The error message seems quite clear, which is why I'm belatedly voting to close as a typo. – Gordon Linoff Jan 22 '21 at 13:46

1 Answers1

3

Use INTO once as follows:

SELECT 
    emp.first_name, emp.last_name INTO _first_name, _last_name
FROM employee emp LIMIT 1

Columns and variables must be in the same sequence respectively.

Popeye
  • 35,427
  • 4
  • 10
  • 31