pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kumar <sgnerd@yahoo.com.sg>
To: Kumar <sgnerd@yahoo.com.sg>
To: Tomasz Myrta <jasiek@klaster.net>
Cc: psql <pgsql-sql@postgresql.org>
Subject: Re: How to avoid nulls while writing string for dynamic query
Date: Fri, 13 Feb 2004 11:11:49 +0530
Message-ID: <009901c3f1f4$1c519a10$7502a8c0@hdsc.com> (raw)
References: <00c001c3f164$1db30140$7502a8c0@hdsc.com>
	<402B74F4.7070604@klaster.net>
	<006701c3f1ed$6610dc30$7502a8c0@hdsc.com>

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" <sgnerd@yahoo.com.sg>
To: "Tomasz Myrta" <jasiek@klaster.net>
Cc: "psql" <pgsql-sql@postgresql.org>
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:  <NULL>
> 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" <jasiek@klaster.net>
> To: "Kumar" <sgnerd@yahoo.com.sg>
> Cc: "psql" <pgsql-sql@postgresql.org>
> 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




view thread (9+ messages)  latest in thread

Message-ID: <009901c3f1f4$1c519a10$7502a8c0@hdsc.com>
Permalink:  ../009901c3f1f4$1c519a10$7502a8c0@hdsc.com/
Also on:    postgresql.org/message-id/009901c3f1f4$1c519a10$7502a8c0@hdsc.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sgnerd@yahoo.com.sg, jasiek@klaster.net
  Subject: Re: How to avoid nulls while writing string for dynamic query
  In-Reply-To: <009901c3f1f4$1c519a10$7502a8c0@hdsc.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox