Sql wer是一个很好的例子。@a_horse_与_no_name:这导致42804:递归查询“pairs”列1的类型字符在非递归术语中变化(3)[],但类型字符在总体上变化[]啊,我假设id是一个整数。最简单的方法是简单地使用text来代替:@a_horse_

Sql wer是一个很好的例子。@a_horse_与_no_name:这导致42804:递归查询“pairs”列1的类型字符在非递归术语中变化(3)[],但类型字符在总体上变化[]啊,我假设id是一个整数。最简单的方法是简单地使用text来代替:@a_horse_,sql,postgresql,Sql,Postgresql,wer是一个很好的例子。@a_horse_与_no_name:这导致42804:递归查询“pairs”列1的类型字符在非递归术语中变化(3)[],但类型字符在总体上变化[]啊,我假设id是一个整数。最简单的方法是简单地使用text来代替:@a_horse_,名称为:Ah,因此text比varchar更适合数组。很高兴知道。你能解释一下为什么吗?@ThorstenKettner,就是这样!工作起来很有魅力!:)谢谢,我已经读了一些关于递归查询的书,我从来没有使用过这个,它很棒@一个没有名字的马:这


wer是一个很好的例子。@a_horse_与_no_name:这导致
42804:递归查询“pairs”列1的类型字符在非递归术语中变化(3)[],但类型字符在总体上变化[]啊,我假设
id
是一个整数。最简单的方法是简单地使用
text
来代替:@a_horse_,名称为:Ah,因此
text
varchar
更适合数组。很高兴知道。你能解释一下为什么吗?@ThorstenKettner,就是这样!工作起来很有魅力!:)谢谢,我已经读了一些关于递归查询的书,我从来没有使用过这个,它很棒@一个没有名字的马:这会导致
42804:递归查询“pairs”列1的类型字符在非递归项中变化(3)[],但类型字符在总体上变化[]。啊,我假设
id
是一个整数。最简单的方法是简单地使用
text
来代替:@a_horse_,名称为:Ah,因此
text
varchar
更适合数组。很高兴知道。你能解释一下为什么吗?@ThorstenKettner,就是这样!工作起来很有魅力!:)谢谢,我已经读了一些关于递归查询的书,我从来没有使用过这个,它很棒!
X1,Y1 ; X2,Y2
X1,Y1 ; X2,Y3
X1,Y2 ; X2,Y1
X1,Y2 ; X2,Y3
X1,Y3 ; X2,Y1
X1,Y3 ; X2,Y2
select (x1, y1) as pair1, (x2, y2) as pair2
from (
    select x.id as x1, y.id as y1
    from x cross join y
    ) p1
join (
    select x.id as x2, y.id as y2
    from x cross join y
    ) p2 on x1 < x2 and y1 <> y2

  pair1  |  pair2  
---------+---------
 (x1,y1) | (x2,y2)
 (x1,y1) | (x2,y3)
 (x1,y2) | (x2,y1)
 (x1,y2) | (x2,y3)
 (x1,y3) | (x2,y1)
 (x1,y3) | (x2,y2)
(6 rows)    
with recursive pairs(supporter_array, supportee_array) as
(
  select ('{' || s.id || '}')::varchar[], ('{' || o.id || '}')::varchar[]
  from (select id, name from support_user order by id fetch first row only) s
  cross join other_user o
  union all
  select p.supporter_array || s.id, p.supportee_array || o.id
  from pairs p
  join support_user s on s.id > ALL (p.supporter_array)
  join other_user o on o.id <> ALL (p.supportee_array)
)
, scenarios as
(
  select *, row_number() over (order by supporter_array, supportee_array) as scenario
  from pairs
  where array_length(supporter_array, 1) = (select count(*) from support_user)
)
select scenario, unnest(supporter_array) as supporter, unnest(supportee_array) as supportee 
from scenarios
order by scenario, supporter;