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 B0DEBD1C515 for ; Fri, 13 Feb 2004 04:53:47 +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 41650-04 for ; Fri, 13 Feb 2004 00:53:24 -0400 (AST) Received: from smtp017.mail.yahoo.com (smtp017.mail.yahoo.com [216.136.174.114]) by svr1.postgresql.org (Postfix) with SMTP id C0C17D1D69B for ; Fri, 13 Feb 2004 00:53:18 -0400 (AST) Received: from unknown (HELO IVESIA67) (sgnerd@203.196.190.138 with login) by smtp017.mail.yahoo.com with SMTP; 13 Feb 2004 04:53:17 -0000 Message-ID: <006701c3f1ed$6610dc30$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "Tomasz Myrta" Cc: "psql" References: <00c001c3f164$1db30140$7502a8c0@hdsc.com> <402B74F4.7070604@klaster.net> Subject: Re: How to avoid nulls while writing string for dynamic query Date: Fri, 13 Feb 2004 10:23:58 +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/132 X-Sequence-Number: 16823 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