Discussion:
How to force Postgres to calculate MAX(boolean)
Andrus
2005-07-07 13:26:35 UTC
Permalink
I try to convert code from other database to Postgres.

CREATE TABLE test(test BOOLEAN);
SELECT MAX(test) FROM test;

causes error

ERROR: function max(boolean) does not exist
HINT: No function matches the given name and argument types. You may need
to add explicit type casts.

I tried
SELECT MAX(test:integer)::boolean FROM test;

but this casuses error

ERROR: cannot cast type boolean to integer

I have lot of MAX() functions applied to boolean expressions.

How to force Postgres to calculate MAX(boolean) ?

MAX(boolean) should return true if its argument evaluates true for at least
one row.



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ***@postgresql.org)
Tom Lane
2005-07-07 15:22:33 UTC
Permalink
Post by Andrus
MAX(boolean) should return true if its argument evaluates true for at least
one row.
We call it bool_or() ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ***@postgresql.org
Ropel
2005-07-07 15:40:07 UTC
Permalink
Post by Andrus
I try to convert code from other database to Postgres.
CREATE TABLE test(test BOOLEAN);
SELECT MAX(test) FROM test;
causes error
ERROR: function max(boolean) does not exist
HINT: No function matches the given name and argument types. You may need
to add explicit type casts.
I tried
SELECT MAX(test:integer)::boolean FROM test;
but this casuses error
ERROR: cannot cast type boolean to integer
I have lot of MAX() functions applied to boolean expressions.
How to force Postgres to calculate MAX(boolean) ?
MAX(boolean) should return true if its argument evaluates true for at least
one row.
Use bool_or(boolean) instead.
Bye




---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Christopher Browne
2005-07-07 17:10:07 UTC
Permalink
Post by Andrus
I try to convert code from other database to Postgres.
CREATE TABLE test(test BOOLEAN);
SELECT MAX(test) FROM test;
causes error
ERROR: function max(boolean) does not exist
HINT: No function matches the given name and argument types. You may need
to add explicit type casts.
I tried
SELECT MAX(test:integer)::boolean FROM test;
but this casuses error
ERROR: cannot cast type boolean to integer
I have lot of MAX() functions applied to boolean expressions.
How to force Postgres to calculate MAX(boolean) ?
MAX(boolean) should return true if its argument evaluates true for at least
one row.
Have you looked into creating a suitable aggregate function yourself?

\h CREATE AGGREGATE

http://www.postgresql.org/docs/current/static/xaggr.html
--
output = reverse("gro.gultn" "@" "enworbbc")
http://linuxdatabases.info/info/rdbms.html
"The test of a principle is whether it applies even to people you
don't like." -- Henry Spencer

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Loading...