D
D
d-virt2016-05-21 14:01:09
PostgreSQL
d-virt, 2016-05-21 14:01:09

How in procedure to write down array of row of the temporary table in var?

Hello.
In a procedure (postgreSQL) I create a temporary table with a random name, from which I then want to select and put the data into a variable.

DECLARE
    temp_table_name TEXT;
    temp_table_records RECORD[]; -- знаю, это не корректно, но как будет правильно?
BEGIN
SELECT INTO temp_table_name CONCAT('temp_manager_operative', floor(random()*(999999-100000)+100000)); -- генерация случайного имени таблицы

EXECUTE 'CREATE TEMP TABLE IF NOT EXISTS ' || temp_table_name || ' (id INT, name TEXT)'; -- создаем временную таблицу

 EXECUTE 'SELECT * FROM ' || temp_table_name INTO temp_table_records ; -- выполняем sql запрос во временную таблицу и кладем результат в переменную

Can you please clarify how you can put the result into a variable without using type creation?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2016-05-21
@melkij

First, why do you need a temporary table?
Secondly, what do you plan to do next?
In the abstract case - it looks like you are trying to invent a cursor www.postgresql.org/docs/current/static/plpgsql-cur...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question