函数 max(bytea) 不存在 postgresql
function max(bytea) does not exist postgresql
我是 PostgreSQL 的新手,我找不到这个问题的解决方案,我需要 select bytea 类型的列中存在的最大值。提前感谢任何帮助。
我的查询:
select MAX (Blob) from test.final
我的错误:
psycopg2.errors.UndefinedFunction: function max(bytea) does not exist
基于 postgresql
文档聚合函数 max()
不支持 bytea
参数。
https://www.postgresql.org/docs/current/functions-aggregate.html
只允许。
any array, numeric, string, or date/time
因为max(bytea)
不可能,你可以试试max(encode(...))
:
postgres=# create table test(name bytea);
CREATE TABLE
postgres=# insert into test values ('1234567890');
INSERT 0 1
postgres=# insert into test values ('12345678901234567890');
INSERT 0 1
postgres=# select * from test;
name
--------------------------------------------
\x31323334353637383930
\x3132333435363738393031323334353637383930
(2 rows)
postgres=# select encode(name,'escape') from test;
encode
----------------------
1234567890
12345678901234567890
(2 rows)
postgres=# select max(encode(name,'escape')) from test;
max
----------------------
12345678901234567890
(1 row)
我是 PostgreSQL 的新手,我找不到这个问题的解决方案,我需要 select bytea 类型的列中存在的最大值。提前感谢任何帮助。
我的查询:
select MAX (Blob) from test.final
我的错误:
psycopg2.errors.UndefinedFunction: function max(bytea) does not exist
基于 postgresql
文档聚合函数 max()
不支持 bytea
参数。
https://www.postgresql.org/docs/current/functions-aggregate.html
只允许。
any array, numeric, string, or date/time
因为max(bytea)
不可能,你可以试试max(encode(...))
:
postgres=# create table test(name bytea);
CREATE TABLE
postgres=# insert into test values ('1234567890');
INSERT 0 1
postgres=# insert into test values ('12345678901234567890');
INSERT 0 1
postgres=# select * from test;
name
--------------------------------------------
\x31323334353637383930
\x3132333435363738393031323334353637383930
(2 rows)
postgres=# select encode(name,'escape') from test;
encode
----------------------
1234567890
12345678901234567890
(2 rows)
postgres=# select max(encode(name,'escape')) from test;
max
----------------------
12345678901234567890
(1 row)