我有以下查询,我想从子查询中插入任意数量的行。当然我得到一个错误SQL Error [21000]: ERROR: more than one row returned by a sub query used as an expression
,因为一些子查询返回多行
insert into logs (_timestap, _message, _mode, _user_id)
select :_timestamp, :_message, :_mode,
case :_mode
-- select all users that have the given grade. NOTE that this sub query returns multiple rows
when 'byGrade' then (select u.id from users u where grade = :_grade)
-- The user id value is already passed
when 'byIndividual' then (select :_user_id limit 1)
-- This sub query also returns multiple rows (all infact) from the users table
when 'everyone' then (select id from users)
end
PostgreSQL 版本 10。
我该如何解决这个问题?