1

I want to store multiple values in single variable(array) in postgresql stored procedure.

My query in mysql is as

select name from cloud_table into @cloud; // @cloud contain multiple name

I want to convert this query into Postgresql. how to achieve this.

2
  • How about using a temporary table instead? select name from cloud_table into #cloud ? Please edit your post and show us how that variable will be used later on. Commented Jan 7, 2019 at 13:12
  • I want to sent multiple cloud name(array) to a function for further operation Commented Jan 7, 2019 at 13:15

1 Answer 1

3

You can store all values in an array.

Something like:

.... 
declare
   l_names text[];
begin
   ...
   select array_agg(name) 
       into l_names
   from cloud_table;

   -- pass the array to a function
   perform some_function(l_names);

   ...
end;

If you already have a function that accepts an array as a parameter and you want to pass the result of your select as an array, you can use:

select your_function(array(select name from cloud_table));
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.