Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6019117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:22:27+00:00 2026-05-23T03:22:27+00:00

I am dynamcially naming temporary table, inserting some data to this dynamic-named temporary table.

  • 0

I am dynamcially naming temporary table, inserting some data to this dynamic-named temporary table.
But I am not able to get back the data from dynamic-named temporary table to function variable to do my calculation.
How can I execute ‘select into ….’ inside plpgsql function from/with dynamic-named temporary table?

drop table dummy;  
drop table mytable;  
create table dummy (id bigint,parent_id bigint);  
insert into dummy values(600,null);  
insert into dummy values(12,600);  
insert into dummy values(700,null);  

DROP FUNCTION total_test(bigint,text,text,date,bigint[],text);  
CREATE OR REPLACE FUNCTION total_test(bigint,text,text,date,dep bigint[],tname text)   RETURNS double precision AS '  
    DECLARE pid BIGINT;  
    DECLARE total DOUBLE PRECISION;  
    DECLARE array_len int;  
    DECLARE myDepIds bigint[];  
    BEGIN   
        IF dep IS NOT NULL THEN  
            total :=0;  
            array_len := array_upper(DEP, 1);  
            EXECUTE ''CREATE TEMPORARY TABLE  '' || tname || ''  (dep_id bigint )'';  
        FOR i IN 1 .. array_len  
            LOOP  
                EXECUTE ''INSERT INTO  '' || tname || ''  values (''|| DEP[i] ||'')'';  
                select into pid id from dummy where parent_id in (DEP[i]);  
                IF pid IS NOT NULL THEN  
                    EXECUTE ''INSERT INTO '' || tname || '' values (''|| pid || '')'';  
                END IF;  
            END LOOP;  
            --works where tname:=''mytable''; select into myDepIds array(select distinct(dep_id) from mytable where dep_id is not null);  
            --not working; EXECUTE ''select into myDepIds array(select distinct(dep_id)   from '' || $7 || '' where dep_id is not null)'';  
            --not working; EXECUTE ''select into myDepIds array(select distinct(dep_id) from '' || tname || '' where dep_id is not null)'';  
        EXECUTE ''select into '' || myDepIds || '' array(select distinct(dep_id) from '' || tname || '' where dep_id is not null)'';  
            --not working; EXECUTE ''select into cast(myDepIds as bigint[]) array(select distinct(dep_id) from '' || tname || '' where dep_id is not null)'';  
            --calculation....  
            --EXECUTE ''DROP TABLE '' || tname;  
            RETURN total;  
        END IF;  
    END;  
' LANGUAGE plpgsql;  

select total_test(11269, 'sales', 'A', date('06/02/2011'), ARRAY[600], 'mytable') as value;  
select * from mytable;  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:22:28+00:00Added an answer on May 23, 2026 at 3:22 am

    Should be:

    EXECUTE sql_string INTO var
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm dynamically inserting some html into the document (by using obj.innerHTML += 'some html').
We're considering using Python (IronPython, but I don't think that's relevant) to provide a
I am currently working on this project which requires me to make a function
For chrome, firefox, and safari the following code seems to work and be able
I dynamically create gridview, and in this grid I have template field also field.HeaderTemplate
Does Oracle have a column metadata for storing its printable friendly label? Say I
I'd like to dynamically apply styles to my views at runtime. Is there any
I'm trying to dynamically segment each generated-label and hardcoded input pair with div tag's.
I am trying to dynamically filter out content using checkboxes and jquery. Being new
I'm dynamically defining a module name from an argument passed on the cli, for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.