Re: Understanding "unknown" data type

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Understanding "unknown" data type
Date: 2011-04-07 18:52:04
Message-ID: 4D9E07D4.1000409@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks Tom.

On 04/07/2011 11:29 AM, Tom Lane wrote:
> Steve Crawford<scrawford(at)pinpointresearch(dot)com> writes:
>> 1. Where can I read up on the purpose and properties of a data-type of
>> unknown?
> It's the type initially imputed to unadorned string literals and NULL...
Is there a place in the documentation that explains this? I haven't
found it so far.

> ...It can be cast to anything, but that's a hardwired behavior not
> something listed in pg_cast.
Hmmm. Not *anything* - at least not directly:

steve=# create table foobar as select '1' as somedata;
WARNING: column "somedata" has type "unknown"
DETAIL: Proceeding with relation creation anyway.
SELECT 1
^
steve=# select somedata::int from foobar;
ERROR: failed to find conversion function from unknown to integer

...
steve=# create table foobar as select '2011-04-07' as somedata;
WARNING: column "somedata" has type "unknown"
DETAIL: Proceeding with relation creation anyway.
SELECT 1
steve=# select somedata::date from foobar;
ERROR: failed to find conversion function from unknown to date

> Throwing an error has been discussed, but it seems likely to break
> things for some people.

A GUC? (Like we need more of those :))
> ...but there aren't terribly bad side-effects
> (other than not being able to operate on that table column). The
> cases that are of practical interest tend to involve label columns in
> views.
Not sure how the variety of front-ends might behave when fed an
"unknown". It's pretty easy to accidentally create such a column and
have it lurking waiting to cause downstream trouble.

For now, I have a daily alert script that warns me if a dev has
accidentally done this.

Cheers,
Steve

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-04-07 19:19:43 Re: Understanding "unknown" data type
Previous Message Tom Lane 2011-04-07 18:29:30 Re: Understanding "unknown" data type