BUG #2905: min and max return incorrect text type

Started by Adriaan van Osabout 19 years ago11 messagesbugs
Jump to latest
#1Adriaan van Os
postgres@microbizz.nl

The following bug has been logged online:

Bug reference: 2905
Logged by: Adriaan van Os
Email address: postgres@microbizz.nl
PostgreSQL version: 8.1.4
Operating system: Mac OS X 10.4.6, intel
Description: min and max return incorrect text type
Details:

Table 9-37. Aggregate Functions in the Postgres docs states that the return
type for min and max is the "same as argument type".

However, min(VARCHAROID) and max(VARCHAROID) return TEXTOID as a result
type.

#2Bruce Momjian
bruce@momjian.us
In reply to: Adriaan van Os (#1)
Re: BUG #2905: min and max return incorrect text type

Adriaan van Os wrote:

The following bug has been logged online:

Bug reference: 2905
Logged by: Adriaan van Os
Email address: postgres@microbizz.nl
PostgreSQL version: 8.1.4
Operating system: Mac OS X 10.4.6, intel
Description: min and max return incorrect text type
Details:

Table 9-37. Aggregate Functions in the Postgres docs states that the return
type for min and max is the "same as argument type".

However, min(VARCHAROID) and max(VARCHAROID) return TEXTOID as a result
type.

Yea, they are internally treated as very similar types.

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#3Adriaan van Os
postgres@microbizz.nl
In reply to: Bruce Momjian (#2)
Re: BUG #2905: min and max return incorrect text type

Bruce Momjian wrote:

Adriaan van Os wrote:

The following bug has been logged online:

Bug reference: 2905
Logged by: Adriaan van Os
Email address: postgres@microbizz.nl
PostgreSQL version: 8.1.4
Operating system: Mac OS X 10.4.6, intel
Description: min and max return incorrect text type
Details:

Table 9-37. Aggregate Functions in the Postgres docs states that the return
type for min and max is the "same as argument type".

However, min(VARCHAROID) and max(VARCHAROID) return TEXTOID as a result
type.

Yea, they are internally treated as very similar types.

But "internally treated as very similar" is still not "same as argument type". Computing requires
exactness.

Adriaan van OS

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Adriaan van Os (#3)
Re: BUG #2905: min and max return incorrect text type

Adriaan van Os wrote:

However, min(VARCHAROID) and max(VARCHAROID) return TEXTOID as a
result type.

Yea, they are internally treated as very similar types.

But "internally treated as very similar" is still not "same as
argument type". Computing requires exactness.

Aside from the apparent discrepancy between the documentation and the
actual behavior, is there an actual use case where this is a problem?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#5Adriaan van Os
postgres@microbizz.nl
In reply to: Peter Eisentraut (#4)
Re: BUG #2905: min and max return incorrect text type

Peter Eisentraut wrote:

Adriaan van Os wrote:

However, min(VARCHAROID) and max(VARCHAROID) return TEXTOID as a
result type.

Yea, they are internally treated as very similar types.

But "internally treated as very similar" is still not "same as
argument type". Computing requires exactness.

Aside from the apparent discrepancy between the documentation and the
actual behavior, is there an actual use case where this is a problem?

Dijkstra's "Rule 0: Don�t Make a Mess of It� <http://www.cs.utexas.edu/users/EWD/&gt; and the virtues
of strong typing, which, for SQL, imply checks at runtime <http://en.wikipedia.org/wiki/Type_safety&gt;.

Besides, the question is absurd. I stumble over a stone on the road, report it and then you ask "is
there an actual use case where this is a problem". Why else do I report it ? What you probably
wanted to ask is: "Apart from the missing warning along the road, couldn't you have walked around
that stone ?"

Well, in answer to that last question, I could have, but that is the wrong approach to computing.

Regards,

Adriaan van Os

#6Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#4)
Re: BUG #2905: min and max return incorrect text type

Peter Eisentraut wrote:

Adriaan van Os wrote:

However, min(VARCHAROID) and max(VARCHAROID) return TEXTOID as a
result type.

Yea, they are internally treated as very similar types.

But "internally treated as very similar" is still not "same as
argument type". Computing requires exactness.

Aside from the apparent discrepancy between the documentation and the
actual behavior, is there an actual use case where this is a problem?

No, I don't think so, and I am reluctant to adjust the documentation to
say "or similar".

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#6)
Re: BUG #2905: min and max return incorrect text type

Bruce Momjian <bruce@momjian.us> writes:

Peter Eisentraut wrote:

Aside from the apparent discrepancy between the documentation and the
actual behavior, is there an actual use case where this is a problem?

No, I don't think so, and I am reluctant to adjust the documentation to
say "or similar".

The documentation is correct as it stands: max(text) returns text.
Adriaan's complaint about max(varchar) is off base because there is
no such function.

regards, tom lane

#8Peter Eisentraut
peter_e@gmx.net
In reply to: Adriaan van Os (#5)
Re: BUG #2905: min and max return incorrect text type

Adriaan van Os wrote:

Besides, the question is absurd. I stumble over a stone on the road,
report it and then you ask "is there an actual use case where this is
a problem". Why else do I report it ? What you probably wanted to ask
is: "Apart from the missing warning along the road, couldn't you have
walked around that stone ?"

No, I'm asking what kind of stone it was and why it is a problem.
--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#9Adriaan van Os
postgres@microbizz.nl
In reply to: Tom Lane (#7)
Re: BUG #2905: min and max return incorrect text type

Tom Lane wrote:

Bruce Momjian <bruce@momjian.us> writes:

Peter Eisentraut wrote:

Aside from the apparent discrepancy between the documentation and the
actual behavior, is there an actual use case where this is a problem?

No, I don't think so, and I am reluctant to adjust the documentation to
say "or similar".

The documentation is correct as it stands: max(text) returns text.
Adriaan's complaint about max(varchar) is off base because there is
no such function.

No, the documentation says that the Argument Type of max and min can be "any array, numeric,
string, or date/time type" and that the Return type is the "same as argument type". The functions
min and max applied to a field of type varchar return a function result of type text. So, if a
max(varchar) function is missing and the cause of the text result type is implicit type casting,
then the fact that there is no max(varchar) function is exactly the bug.

Adriaan van Os

#10Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Adriaan van Os (#9)
Re: BUG #2905: min and max return incorrect text type

Adriaan van Os wrote:

Tom Lane wrote:

Bruce Momjian <bruce@momjian.us> writes:

Peter Eisentraut wrote:

Aside from the apparent discrepancy between the documentation and the
actual behavior, is there an actual use case where this is a problem?

No, I don't think so, and I am reluctant to adjust the documentation to
say "or similar".

The documentation is correct as it stands: max(text) returns text.
Adriaan's complaint about max(varchar) is off base because there is
no such function.

No, the documentation says that the Argument Type of max and min can be
"any array, numeric, string, or date/time type" and that the Return type is
the "same as argument type". The functions min and max applied to a field
of type varchar return a function result of type text. So, if a
max(varchar) function is missing and the cause of the text result type is
implicit type casting, then the fact that there is no max(varchar) function
is exactly the bug.

Do you have a specific situation on which this causes a problem for you?
I mean, are you asking because it really bugs you, or just for the sake
of being pedantic?

--
Alvaro Herrera Valdivia, Chile ICBM: S 39� 49' 18.1", W 73� 13' 56.4"
Tulio: oh, para qu� servir� este boton, Juan Carlos?
Policarpo: No, al�jense, no toquen la consola!
Juan Carlos: Lo apretar� una y otra vez.

#11Bruce Momjian
bruce@momjian.us
In reply to: Alvaro Herrera (#10)
Re: BUG #2905: min and max return incorrect text type

Alvaro Herrera wrote:

Adriaan van Os wrote:

Tom Lane wrote:

Bruce Momjian <bruce@momjian.us> writes:

Peter Eisentraut wrote:

Aside from the apparent discrepancy between the documentation and the
actual behavior, is there an actual use case where this is a problem?

No, I don't think so, and I am reluctant to adjust the documentation to
say "or similar".

The documentation is correct as it stands: max(text) returns text.
Adriaan's complaint about max(varchar) is off base because there is
no such function.

No, the documentation says that the Argument Type of max and min can be
"any array, numeric, string, or date/time type" and that the Return type is
the "same as argument type". The functions min and max applied to a field
of type varchar return a function result of type text. So, if a
max(varchar) function is missing and the cause of the text result type is
implicit type casting, then the fact that there is no max(varchar) function
is exactly the bug.

Do you have a specific situation on which this causes a problem for you?
I mean, are you asking because it really bugs you, or just for the sake
of being pedantic?

And what suggestion do you have for a change? How would you like the
documentation wording changed?

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +