I'm trying to indicate superusers in a USERS/GROUPS data model as follows:
create table users (user_id int);
create table groups (group_id int, superuser boolean);
create table usergroup( user_id int, group_id int );
select users.user_id,
('t' = any( array_agg('superuser') ))
from users
left join usergroup using(user_id)
left join groups using (group_id)
group by user_id
but Postgres (9.1) tells me:
error : ERROR: could not determine polymorphic type because input has type "unknown"
From this I gather that I should be adding an explicit Cast somewhere, but I can't figure out where. Can anyone advise?
I'd like an explained answer if possible, so I can learn from this
Your query can be fixed like this:
You were doing array_agg on 'superuser' text literal, instead of the superuser column.
I would write it like so: