pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed::text problem
3+ messages / 2 participants
[nested] [flat]
* ::text problem
@ 2003-11-25 12:37 Kumar <sgnerd@yahoo.com.sg>
0 siblings, 1 reply; 3+ messages in thread
From: Kumar @ 2003-11-25 12:37 UTC (permalink / raw)
To: pgsql-sql
Hi ,
I am running postgres 7.3.4 on Linux 7.2. I wanna print 'Not Supplied' if 'c1' column of datatype - 'timestamp' is null. For that I am using case statement
SELECT
CASE WHEN c1 IS NULL THEN 'Record_Not_Found'ELSE c1 END as approval_date
FROM t1;
ERROR: Bad timestamp external representation 'Record_Not_Found'
SELECT
CASE WHEN c1 IS NULL THEN 'Record_Not_Found'::text ELSE c1 END as approval_date
FROM t1;
ERROR: CASE types 'timestamp without time zone' and 'text' not matched
Where I am doing wrong? Please shed some light.
Regards
Senthil Kumar S
DBA
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ::text problem
@ 2003-11-25 16:14 Richard Huxton <dev@archonet.com>
parent: Kumar <sgnerd@yahoo.com.sg>
0 siblings, 1 reply; 3+ messages in thread
From: Richard Huxton @ 2003-11-25 16:14 UTC (permalink / raw)
To: Kumar <sgnerd@yahoo.com.sg>; pgsql-sql
On Tuesday 25 November 2003 12:37, Kumar wrote:
>
> SELECT
> CASE WHEN c1 IS NULL THEN 'Record_Not_Found'ELSE c1 END as
> approval_date FROM t1;
> ERROR: Bad timestamp external representation 'Record_Not_Found'
>
>
> SELECT
> CASE WHEN c1 IS NULL THEN 'Record_Not_Found'::text ELSE c1 END as
> approval_date FROM t1;
> ERROR: CASE types 'timestamp without time zone' and 'text' not matched
Almost - you're on the right lines. Try:
SELECT
CASE
WHEN c1 IS NULL THEN 'Record_Not_Found'::text
ELSE c1::text
END as approval_date FROM t1;
You need to make sure both options return type text.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ::text problem
@ 2003-11-26 07:03 Kumar <sgnerd@yahoo.com.sg>
parent: Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 3+ messages in thread
From: Kumar @ 2003-11-26 07:03 UTC (permalink / raw)
To: Richard Huxton <dev@archonet.com>; pgsql-sql
Thanks a lot. It worked.
----- Original Message -----
From: "Richard Huxton" <dev@archonet.com>
To: "Kumar" <sgnerd@yahoo.com.sg>; "psql" <pgsql-sql@postgresql.org>
Sent: Tuesday, November 25, 2003 9:44 PM
Subject: Re: [SQL] ::text problem
> On Tuesday 25 November 2003 12:37, Kumar wrote:
> >
> > SELECT
> > CASE WHEN c1 IS NULL THEN 'Record_Not_Found'ELSE c1 END as
> > approval_date FROM t1;
> > ERROR: Bad timestamp external representation 'Record_Not_Found'
> >
> >
> > SELECT
> > CASE WHEN c1 IS NULL THEN 'Record_Not_Found'::text ELSE c1 END as
> > approval_date FROM t1;
> > ERROR: CASE types 'timestamp without time zone' and 'text' not matched
>
> Almost - you're on the right lines. Try:
> SELECT
> CASE
> WHEN c1 IS NULL THEN 'Record_Not_Found'::text
> ELSE c1::text
> END as approval_date FROM t1;
>
> You need to make sure both options return type text.
>
> --
> Richard Huxton
> Archonet Ltd
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-11-26 07:03 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-11-25 12:37 ::text problem Kumar <sgnerd@yahoo.com.sg>
2003-11-25 16:14 ` Richard Huxton <dev@archonet.com>
2003-11-26 07:03 ` Kumar <sgnerd@yahoo.com.sg>
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