数组_agg alterantive-PostgreSQL
我使用的是postgreSQL版本8.3.4,它不支持函数array\u agg 我对这些表格的定义如下:数组_agg alterantive-PostgreSQL,sql,postgresql,Sql,Postgresql,我使用的是postgreSQL版本8.3.4,它不支持函数array\u agg 我对这些表格的定义如下: create table photos (id integer, user_id integer, primary key (id, user_id)); create table tags (photo_id integer, user_id integer, info text, primary key (user_id, photo_id, info)); 我遇到了这个问题,它
create table photos (id integer, user_id integer, primary key (id, user_id));
create table tags (photo_id integer, user_id integer, info text, primary key (user_id, photo_id, info));
我遇到了这个问题,它提供了我所需要的:
SELECT photo_id
FROM tags t
GROUP BY 1
HAVING (SELECT count(*) >= 1
FROM (
SELECT photo_id
FROM tags
WHERE info = ANY(array_agg(t.info))
AND photo_id <> t.photo_id
GROUP BY photo_id
HAVING count(*) >= 1
) t1
)
但我不能用它,因为我的版本。
除了这个问题,我还有其他的问题可以使用吗
select
t2.photo_id, count(*)
from tags t1
join tags t2 on t1.info = t2.info and t1.photo_id <> t2.photo_id
group by t2.photo_id
;
如果你想要精确的k,那么让count=k,Postgres 8.3已经失去了近三年的支持。您应该升级到当前版本,而不是尝试使用如此旧的版本寻找解决方法。感谢您的提示,这不取决于我。两个表都使用post ddl?。您是指创建表定义吗?张贴。无论是谁,都需要在无法言说的事情上狠狠地踢一脚。15-20年后,他们会等到无法获得运行8.3操作系统的硬件再升级吗?或者将其封装在模拟器中并继续运行,成本和复杂性不断增加?没有升级路径是荒谬的,就是这样,离开它太长了。