From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: coalesce with all nulls can only be assigned to text |
Date: | 2006-11-29 18:15:40 |
Message-ID: | 21074.1164824140@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> writes:
> [ "coalesce(null, null)" yields type TEXT ]
Well, it has to yield *something*. You'd get the same result from
"coalesce('2006-11-29', '2006-11-30')" ... you might think this looks
like dates, but it's just some untyped literals and the parser chooses
to resolve those as TEXT if there's no other clue anywhere in the
expression.
If you cast at least one of the nulls to DATE, you'll get what you want.
regression=# create table test_coalesce(f1 int not null, f2 date);
CREATE TABLE
regression=# insert into test_coalesce values (2, coalesce(null, null));
ERROR: column "f2" is of type date but expression is of type text
HINT: You will need to rewrite or cast the expression.
regression=# insert into test_coalesce values (2, coalesce(null::date, null));
INSERT 0 1
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Vivek Khera | 2006-11-29 18:24:25 | Re: Postgresql data integrity during RAID10 drive rebuild |
Previous Message | Ritesh Nadhani | 2006-11-29 18:15:01 | Re: Development of cross-platform GUI for Open Source DBs |