"Kevin Grittner" <kevin.gritt...@wicourts.gov> writes: > Tom Lane <t...@sss.pgh.pa.us> wrote: >> "Kevin Grittner" <kevin.gritt...@wicourts.gov> writes: >>> Still, it rates pretty high on my astonishment scale that a >>> COALESCE of two untyped NULLs (or for that matter, any two values >>> of unknown type) returns a text value. >> >> What would you have it do instead, throw an error? > Return a value of unknown type. That would require doing actual computation on values of unknown type.
In the specific case of COALESCE, we could theoretically do that, since the only computation it needs is "IS NULL" which is datatype-independent. In most situations, however, you can't evaluate the function without knowledge of the datatype semantics. As an example, consider NULLIF('0', '00'). This gives different answers if you suppose the literals are text than if you suppose they are integers. So yeah, we could make COALESCE into a special-case wart in the type system and have it able to execute without inferring a type for the arguments. I don't think that would be a net improvement in the system's astonishment quotient, however; people would just be confused why COALESCE behaves differently from everything else. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers