0

This doesn't work:

DO
$do$
    DECLARE
        nested   varchar[][] := '{{a},{b},{c}}';
        unnested varchar[];
    BEGIN    
        unnested := unnest(nested)::text[];
    END
$do$;

Because, it seems, the unnest expression returns a table. The error message is:

[22P02] ERROR: malformed array literal: "a" Detail: Array value must start with "{" or dimension information. Where: SQL statement "SELECT unnest(nested)::text[]" PL/pgSQL function inline_code_block line 7 at assignment

So I guess the solution is to create an array out of the unnest return value? How do I do this?

1 Answer 1

1

You can't cast the result of a set returning function to an array.

DO
$do$
DECLARE
  nested   varchar[][] := '{{a},{b},{c}}';
  unnested varchar[];
BEGIN    
  unnested := array(select * from unnest(nested));
END
$do$;
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.