Hi Hackers,

I have created a table with an unknown column in it.

CREATE table test AS select 'a' as columna, 'b' as columnb;

will create a table with columna and columnb as an unknown type.

This in itself is not strictly a problem.  However there are not functions in 
postgresql to convert unknown to another value.
There are functions if you do explicit casts, but when extracting data from a table it 
is not possible.
So this creates a problem where you cannot cast the value of the column to anything 
else.  Attempting to change the column type on 8.0b4
or even trying to do select columna::text from test results in the following error.

SQL error:

ERROR:  failed to find conversion function from "unknown" to text

In statement:
ALTER TABLE "test" ALTER COLUMN "columna" TYPE text

I would have assumed there was an implicit cast to text for items in the format 'a', 
but it seems not.

I have spoken to Gavin Sherry on IRC and he has made functions to allow casting from 
unknown to text in this situation, however he has
not had an opportunity to send a mail to the list about this issue.  So I am doing it.

Neil Conway also made some comments about unknown being as issue that has a low 
priority, however I think we need to either be able to cast away from
unknown, or at least error when attempting to create a table with an unknown column 
type.

I get the same error on 7.4.5 and 8.0b4

Regards

Russell Smith

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply via email to