max() unexpected type conversion

From: Hélder M(dot) Vieira <hmv(at)mail(dot)telepac(dot)pt>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: max() unexpected type conversion
Date: 2005-11-21 12:47:40
Message-ID: 000901c5ee99$c275e380$580bfea9@hmv02
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2005-11-21 15:03:45 Re: max() unexpected type conversion
Previous Message Adrian Klaver 2005-11-20 23:35:57 Re: Is it possible to redirect an update/insert/delete to a different table?