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 15958D1D8F3 for ; Fri, 13 Feb 2004 07:12: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 70326-03 for ; Fri, 13 Feb 2004 03:12:46 -0400 (AST) Received: from smtp104.mail.sc5.yahoo.com (smtp104.mail.sc5.yahoo.com [66.163.169.223]) by svr1.postgresql.org (Postfix) with SMTP id 9C013D1D8AE for ; Fri, 13 Feb 2004 03:12:44 -0400 (AST) Received: from unknown (HELO IVESIA67) (sgnerd@203.196.190.138 with login) by smtp104.mail.sc5.yahoo.com with SMTP; 13 Feb 2004 07:12:44 -0000 Message-ID: <00c801c3f200$e117eff0$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "Tomasz Myrta" Cc: "psql" References: <00c001c3f164$1db30140$7502a8c0@hdsc.com> <402B74F4.7070604@klaster.net> <006701c3f1ed$6610dc30$7502a8c0@hdsc.com> <402C6FB8.8000606@klaster.net> Subject: Re: How to avoid nulls while writing string for dynamic query Date: Fri, 13 Feb 2004 12:43:26 +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/138 X-Sequence-Number: 16829 oh, ok understood. What will happen for a timestamp field. Let us say c1 is a timestamp column. sqlstr := 'insert into test(c1, c2) values ('||'\''||COALESCE(rec.c1,'NULL')||'\',' > > ||'\''||rec.c2||'\')'; If this case the query will be insert into test(c1,c2) values ('2004-02-13', 'Hai') If there is a null value encountered i will return an error for the following query insert into test(c1,c2) values ('NULL', 'Hai') ERROR: Bad timestamp external representation 'NULL' I think using 'CASE' this could be solved. But instead is there any other simple way to do it. Thanks a lot Mr. Tomasz Myrta Kumar ----- Original Message ----- From: "Tomasz Myrta" To: "Kumar" Cc: "psql" Sent: Friday, February 13, 2004 12:03 PM Subject: Re: [SQL] How to avoid nulls while writing string for dynamic query > Dnia 2004-02-13 05:53, Użytkownik Kumar napisał: > > > I am having problem there. see what happens > > > > sqlstr := 'insert into test(c1, c2) values ('||COALESCE(rec.c1,'NULL')||',' > > ||'\''||rec.c2||'\')'; > > You are preparing a string, so make sure you have strings everywhere: > sqlstr := 'insert into test(c1, c2) values > ('||COALESCE(rec.c1::text,'NULL')||','||'\''||rec.c2||'\')'; > > Regards, > Tomasz Myrta