Search code examples
postgresqldbeaver

DBeaver PostgreSql script variables - array


I'm looking to use a query which takes an array of known values, to be declared as a variable, but cant seem to get the syntax, or find the relevant help/documentation. Would anyone be able to offer thoughts on the following:

Running:

select unnest (array['[email protected]', '[email protected]']);

produces a list of array items, but I'd like to replace the hardcoded list with a variable.

I've tried various permutations of things like:

@set emails = ['[email protected]', '[email protected]'];
select :emails;
select unnest (array(:emails));

but am getting syntax errors that I cant unpick.

Would anyone be able to point out my error?...many thanks in advance


Solution

  • You can store the array creation, and work with it as a regular array

    @set emails = ARRAY['[email protected]', '[email protected]']
    select unnest (:emails);
    

    PS: note that there is no ; at the end of the @set statement, else it would be part of the saved variable