我有一个函数,通过
output parameters返回两个参数作为匿名复合类型.
我可以使用如下查询访问各列:
# select * from guess_user('Joe','Bloggs'); confidence | matchid ------------+--------- 0.142857 | 1121
# select firstname,lastname from users limit 5; firstname | lastname -----------+---------- Adam | Smith Amy | Peters Annette | Bloggs Annie | Mills Amanda | Hibbins
firstname | lastname | confidence | matchid -----------+----------+------------+--------- Adam | Smith | | Amy | Peters | | Annette | Bloggs | | Annie | Mills | | Amanda | Hibbins | |
使用调用guess_user的结果填充置信度和匹配列,并使用该行中的名称.
我目前最近的努力是:
# select firstname,lastname,guess_user(firstname,lastname) from users limit 5;
哪个回报:
firstname | lastname | guess_user -----------+-----------+--------------- Angela | Abbott | (0.285714,3) Amy | Allan | (0.285714,4) Annette | Allison | (0.285714,5) Annie | Ashworth | (0.285714,6) Amanda | Baird | (0.285714,7)
有没有办法将guess_user输出拆分为单独的列?
解决方法
结合depesz和fazal的答案,这似乎有效:
select firstname,(guess_user(firstname,lastname)).* from users limit 5