X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 76BE8D1DD7B for ; Sun, 15 Feb 2004 19:50:58 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 72492-01 for ; Sun, 15 Feb 2004 15:50:58 -0400 (AST) Received: from serwer.skawsoft.com.pl (skawina.eu.org [80.48.213.66]) by svr1.postgresql.org (Postfix) with ESMTP id 3A456D1DD79 for ; Sun, 15 Feb 2004 15:50:56 -0400 (AST) Received: from klaster.net (backbone.zab.citynet.pl [212.244.6.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 504E22B3CB; Sun, 15 Feb 2004 20:50:39 +0100 (CET) Message-ID: <402FCE48.4010902@klaster.net> Date: Sun, 15 Feb 2004 20:53:44 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.6) Gecko/20040113 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Senthil Kumar S Cc: psql Subject: Re: writing a dynamic sql References: <01b201c3efbb$097a2af0$7502a8c0@hdsc.com> In-Reply-To: <01b201c3efbb$097a2af0$7502a8c0@hdsc.com> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/184 X-Sequence-Number: 16874 Dnia 2004-02-10 10:48, Użytkownik Senthil Kumar S napisał: > Dear friends, > > I am having an lengthy SQL, which will be called every conditions of > if...else statement. I tried with passing that via a string and execute it. > But I got error. > v_sql := > 'INSERT INTO activities( > activity_id, > parent_activity_id, > activity_type_id, > subject, > description, > category_id, > priority_id, > activity_start_time, > activity_end_time, > ) > VALUES ( > NEXTVAL(\'seq_activities\'), > rec_recurrence.activity_id, > rec_activity.activity_type_id, > rec_activity.subject, > rec_activity.description, > rec_activity.category_id, > rec_activity.priority_id, > rec_activity.activity_start_time, > rec_activity.activity_end_time > );'; > > execute v_sql; > > I got an error saying that the record variable which I declared earlier is > not having reference (or it does not exists). > > Any suggestion to pack this inside a dynamic function and call it inside > many if conditions. Your v_sql variable *must* contain static text only. It can't have any references to variables. Here is little example how your query should look like: ... VALUES ( NEXTVAL(\'seq_activities\'), '' || rec_recurrence.activity_id::text || '','' || rec_activity.activity_type_id::text ... After this v_sql will be: VALUES ( NEXTVAL(\'seq_activities\'),1,2,... Regards, Tomasz Myrta