max() unexpected type conversion - Mailing list pgsql-sql

From Hélder M. Vieira
Subject max() unexpected type conversion
Date
Msg-id 000901c5ee99$c275e380$580bfea9@hmv02
Whole thread Raw
Responses Re: max() unexpected type conversion
List pgsql-sql
Hello.

I'm having some trouble with an unexpected conversion performed by the max() 
function.
If max() operates on a 'varchar' type column, the result appears with 'text' 
type.
Should I expect this behaviour in the current and later versions ?

I mention this because I'm using ODBC in VB, and this type conversion has a 
bad outcome, because 'text' columns require a specific treatment (a second 
reading of the column contents returns null). Therefore, if this conversion 
is beeing made as a result of a design option, I'll have to use a different 
approach (something like 'select ... order by ... desc limit 1').

A small sample follows, giving a 'text' type result:


create table test
( testcol varchar(4) not null
);

insert into test (testcol) values ('A');
insert into test (testcol) values ('A');
insert into test (testcol) values ('B');
insert into test (testcol) values ('B');
insert into test (testcol) values ('C');
insert into test (testcol) values ('C');

select max(testcol) from test;



Thank you

Hélder M. Vieira




pgsql-sql by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Is it possible to redirect an update/insert/delete to a different table?
Next
From: Tom Lane
Date:
Subject: Re: max() unexpected type conversion