PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 4th, 2012, 01:41 PM
PM_Support PM_Support is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 1 PM_Support User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 27 sec
Reputation Power: 0
Function with variables/insert/for loop problems

I am using DreamCoder as my front end to my PostgreSQL database. It has an import feature into the database that is very helpful. I have created a function that is called inside the after_import function.

The function needs to call distinct names in the name table and loop through them. When the name = x, all the entries in my task table with the name x and sent to that person's task table, which is named x.

I know this is confusing but I am having serious errors and since I am new to PostgreSQL any help would be appreciated.

Here is my function:

Code:
CREATE OR REPLACE FUNCTION table_name()
  RETURNS text AS
$BODY$
DECLARE
     table_name TEXT;
BEGIN

    FOR table_name IN SELECT DISTINCT "Name_ITable" FROM "import_to_Task"
    LOOP
        EXECUTE 'INSERT INTO ' || table_name || ' ("Task_TTable") (SELECT DISTINCT "import_to_Task"."Task_ITable" FROM "import_to_Task" WHERE "Task_ITable" <> ALL (SELECT ' || table_name ||'."Task_TTable" FROM ' || table_name || '));';
    END LOOP;
RETURN NULL;

END
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION new_name()
  OWNER TO postgres;


The error that I am getting is that the column "x" does not exist (where table_name = x). So, I need to reference the text 'x' but it is coming out just x (no apostrophes).

Thanks in advance for any help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Function with variables/insert/for loop problems

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap