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 6A13DD1B4B5 for ; Fri, 13 Feb 2004 05:41:28 +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 51807-01 for ; Fri, 13 Feb 2004 01:41:22 -0400 (AST) Received: from smtp105.mail.sc5.yahoo.com (smtp105.mail.sc5.yahoo.com [66.163.169.225]) by svr1.postgresql.org (Postfix) with SMTP id 19A3ED1B4C9 for ; Fri, 13 Feb 2004 01:41:21 -0400 (AST) Received: from unknown (HELO IVESIA67) (sgnerd@203.196.190.138 with login) by smtp105.mail.sc5.yahoo.com with SMTP; 13 Feb 2004 05:41:20 -0000 Message-ID: <009901c3f1f4$1c519a10$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "Kumar" , "Tomasz Myrta" Cc: "psql" References: <00c001c3f164$1db30140$7502a8c0@hdsc.com> <402B74F4.7070604@klaster.net> <006701c3f1ed$6610dc30$7502a8c0@hdsc.com> Subject: Re: How to avoid nulls while writing string for dynamic query Date: Fri, 13 Feb 2004 11:11:49 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-2" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/134 X-Sequence-Number: 16825 Dear all, I solved it using ISNULL function. sqlstr := 'insert into test(c1, c2) values ('||ISNULL(rec.c1,'NULL')||',' > ||'\''||rec.c2||'\')'; Thanks kumar ----- Original Message ----- From: "Kumar" To: "Tomasz Myrta" Cc: "psql" Sent: Friday, February 13, 2004 10:23 AM Subject: Re: [SQL] How to avoid nulls while writing string for dynamic query > I am having problem there. see what happens > > sqlstr := 'insert into test(c1, c2) values ('||COALESCE(rec.c1,'NULL')||',' > ||'\''||rec.c2||'\')'; > > WARNING: Error occurred while executing PL/pgSQL function test_fn > WARNING: line 8 at assignment > ERROR: pg_atoi: error in "NULL": can't parse "NULL" > > Dont forgot that c1 is int. > > when i have like this > sqlstr := 'insert into test(c1, c2) values ('||COALESCE(rec.c1,NULL)||',' > ||'\''||rec.c2||'\')'; > > NOTICE: > WARNING: Error occurred while executing PL/pgSQL function test_fn > WARNING: line 11 at execute statement > ERROR: cannot EXECUTE NULL query > > That is the problem i am facing. Please shed some light. > > Thanks > Kumar > > ----- Original Message ----- > From: "Tomasz Myrta" > To: "Kumar" > Cc: "psql" > Sent: Thursday, February 12, 2004 6:13 PM > Subject: Re: [SQL] How to avoid nulls while writing string for dynamic query > > > > Dnia 2004-02-12 13:31, Użytkownik Kumar napisał: > > > The error is because of no value for column c1. If the column c1 is a > > > string I might have replace it with empty string. I don't want to > > > substitute with '0' which could work. > > > > > > sqlstr := 'insert into test(c1, c2) values (' ||ISNULL(rec.c1,'0')||',' > > > > > > ||'\''||rec.c2||'\')'; > > > > Substitute it with NULL value: > > sqlstr := 'insert into test(c1, c2) values(' || coalesce(rec.c1,'NULL') > > ||... > > > > Regards, > > Tomasz Myrta > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings