From: | "Kumar" <sgnerd(at)yahoo(dot)com(dot)sg> |
---|---|
To: | "Tomasz Myrta" <jasiek(at)klaster(dot)net> |
Cc: | "psql" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: How to avoid nulls while writing string for dynamic query |
Date: | 2004-02-13 07:13:26 |
Message-ID: | 00c801c3f200$e117eff0$7502a8c0@hdsc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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" <jasiek(at)klaster(dot)net>
To: "Kumar" <sgnerd(at)yahoo(dot)com(dot)sg>
Cc: "psql" <pgsql-sql(at)postgresql(dot)org>
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
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2004-02-13 07:22:17 | Re: 7.4 - FK constraint performance |
Previous Message | Tomasz Myrta | 2004-02-13 06:33:28 | Re: How to avoid nulls while writing string for dynamic query |