Guglie
Guglie

Reputation: 2441

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;

Upvotes: 7

Views: 8544

Answers (1)

Guglie
Guglie

Reputation: 2441

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.

Upvotes: 26

Related Questions