pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
max() unexpected type conversion
3+ messages / 2 participants
[nested] [flat]

* max() unexpected type conversion
@ 2005-11-21 12:47 Hélder M. Vieira <hmv@mail.telepac.pt>
  2005-11-21 15:03 ` Re: max() unexpected type conversion Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Hélder M. Vieira @ 2005-11-21 12:47 UTC (permalink / raw)
  To: 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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: max() unexpected type conversion
  2005-11-21 12:47 max() unexpected type conversion Hélder M. Vieira <hmv@mail.telepac.pt>
@ 2005-11-21 15:03 ` Tom Lane <tgl@sss.pgh.pa.us>
  2005-11-22 01:40   ` Re: max() unexpected type conversion Hélder M. Vieira <hmv@mail.telepac.pt>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2005-11-21 15:03 UTC (permalink / raw)
  To: Hélder M. Vieira <hmv@mail.telepac.pt>; +Cc: pgsql-sql

"=?iso-8859-1?Q?H=E9lder_M._Vieira?=" <hmv@mail.telepac.pt> writes:
> 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 ?

This is true of just about everything, not only max() -- there are *no*
functions yielding varchar in recent PG releases.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: max() unexpected type conversion
  2005-11-21 12:47 max() unexpected type conversion Hélder M. Vieira <hmv@mail.telepac.pt>
  2005-11-21 15:03 ` Re: max() unexpected type conversion Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-11-22 01:40   ` Hélder M. Vieira <hmv@mail.telepac.pt>
  0 siblings, 0 replies; 3+ messages in thread

From: Hélder M. Vieira @ 2005-11-22 01:40 UTC (permalink / raw)
  To: pgsql-sql

> This is true of just about everything, not only max() -- there are *no*
> functions yielding varchar in recent PG releases

Thanks for the information. I added an explicit cast to the max() output and
it works fine.

Anyway, for those using VB, this is potentially hazardous. Knowing that the
underlying data is of type 'varchar', one has to be always very cautious
about the 'text' conversion, otherwise all readings after the first will
return null instead of valid data.



Helder M. Vieira





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-11-22 01:40 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-21 12:47 max() unexpected type conversion Hélder M. Vieira <hmv@mail.telepac.pt>
2005-11-21 15:03 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-11-22 01:40   ` Hélder M. Vieira <hmv@mail.telepac.pt>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox