Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: INTO specified more than once at or near "INTO"

Inside a postgresql function I'm trying to get two values selected from a table into two variables, but I get this error:

INTO specified more than once at or near "INTO"

This is the (pseudo)code:

CREATE OR REPLACE FUNCTION func() RETURNS TRIGGER AS
$$ 
DECLARE
    a numeric;
    b varchar(20);
    c numeric;
BEGIN
    IF ... THEN
        ...

        SELECT x INTO a FROM t1 WHERE y = 1

        IF a > 5 THEN
            SELECT m, n INTO b, c FROM t2 WHERE ...;
            ...
        END IF;
    END IF;
END
$$ LANGUAGE plpgsql;
like image 574
Guglie Avatar asked Sep 14 '13 15:09

Guglie


1 Answers

The problem is just (as always) a missing semicolon.

Just add the missing semicolon on the first SELECT statement

[...]

    SELECT x INTO a FROM t1 WHERE y = 1; #missing semicolon

    IF a > 5 THEN
        SELECT m, n INTO b ...;
[...]

The INTO specified more than once error is generated from the second SELECT statement (when it finds a second INTO) and it doesn't suggest much about where to find the problem.

like image 93
Guglie Avatar answered Nov 16 '22 20:11

Guglie