auto type casting bug - Mailing list pgsql-bugs

From Matthew Manuel
Subject auto type casting bug
Date
Msg-id 430E2477.6010804@peer1.net
Whole thread Raw
Responses Re: auto type casting bug
List pgsql-bugs
Hello, I found a strange error which occurs when I run a query from
PHP4, where if there is a column which has strings arbitrarily defined
text for all rows of a sub-select, and you attempt to sort by that
column, it cannot determine the type for that column in order to do the
sort.

- If you UNION more than one of these rows, the UNION seems to determine
the data type for the column, so the sort works.
- If the values are integers, the error does not occur
- if each arbitrary text value is explicitly cast, the error does not
occur. I have not tested other data types.
- This error does NOT occur when the query is run in the psql command line.

If you have any8 questions, please feel free to contact me.

Thanks,
    -Matthew

Here is an example PHP page I wrote to demonstrate:

query1:
SELECT a.col1, a.col2
FROM (
    SELECT 'test row' AS col1, 1 AS col2
) AS a
ORDER BY a.col1
Running...


*Warning*:  pg_query(): Query failed: ERROR:  failed to find conversion function from "unknown" to text in
*/home3/manuel.ca/test/pgtest.php*on line *14* 

done

 query2:
SELECT a.col1, a.col2
FROM (
    SELECT 'test row' AS col1, 1 AS col2
) AS a
ORDER BY a.col2
Running...
done

 query3:
SELECT a.col1, a.col2
FROM (
    SELECT 'test row' AS col1, 1 AS col2
    UNION
    SELECT 'next row' AS col1, 2 AS col2
) AS a
ORDER BY a.col1
Running...
done

 query4:
SELECT a.col1, a.col2
FROM (
    SELECT 'test row'::text AS col1, 1 AS col2
) AS a
ORDER BY a.col1
Running...
done

pgsql-bugs by date:

Previous
From: Gennadiy.Donchyts@gmail.com
Date:
Subject: Re: BUG #1844: Failed to start service 'PostgreSQL Database Server 8.0'
Next
From: "Eric Boutin"
Date:
Subject: BUG #1848: Segfault with pg_dump when database name omitted