3

I have the following pl/pgsql function. (Obviously, this is not the full function, it's just the minimal amount of code needed to reproduce the problem)

CREATE OR REPLACE FUNCTION test_func(infos TEXT[][])
RETURNS void AS
$$
DECLARE
    info TEXT[];
    type TEXT[];
    name TEXT;
BEGIN
    FOREACH info SLICE 1 IN ARRAY infos LOOP
        RAISE NOTICE 'Stuff: %', info;
        type := info[1];
        name := info[2];
        RAISE NOTICE 'Done with stuff';
    END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;

When I run the function using SELECT test_func('{{something, things},{other, data}}'::TEXT[][]);, I get the following output:

NOTICE:  Stuff: {something,things}
ERROR:  malformed array literal: "something"
DETAIL:  Array value must start with "{" or dimension information.
CONTEXT:  PL/pgSQL function test_func(text[]) line 10 at assignment

I don't understand how this error is happening. When the value of info is printed, it shows {something,things}, which seems to me to be a proper array literal.

I am using PostgreSQL version 9.4.7, in case it matters.

1 Answer 1

4

The variable type should be text (not text[]):

CREATE OR REPLACE FUNCTION test_func(infos TEXT[][])
RETURNS void AS
$$
DECLARE
    info TEXT[];
    type TEXT;
    name TEXT;
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.