Home > Net >  PostgreSQL error: ERROR: subplan "InitPlan 1 (returns $0)" was not initialized
PostgreSQL error: ERROR: subplan "InitPlan 1 (returns $0)" was not initialized

Time:07-14

Hi everyone I run my query on dbeaver and get this error:

SQL Error [XX000]: ERROR: subplan "InitPlan 1 (returns $0)" was not initialized Where: parallel worker

Do you know how to solve this? I've looking for the solution but didn't find a proper one.

CodePudding user response:

That is very obviously a bug. If that is plain PostgreSQL, please report it to the project (including a detailed reproducer, which you forgot here). If you are using some hacked up fork of PostgreSQL, report the problem to the vendor.

CodePudding user response:

I think I found the problem. Here is my initial query that lead to the error:

select * from (
select distinct
    email,
    case 
    when extract(day from table2.join_date::date) <= 15
        then (to_char(date_trunc('month', table2.join_date::date   interval '1 month'),'yyyy-mm-dd'))::date
    else (to_char(date_trunc('month', table2.join_date::date   interval '2 month'),'yyyy-mm-dd'))::date
    end as start_date
from table1
left join table2 on table1.email = table2.email
) base
where start_date < (select to_char(date_trunc('month',current_date),'yyyy-mm-dd'))::date

I think if you do complex subquery using heavy table, it will lead to this error.

So the solution is you should using CTE instead of subquery. I don't know if this is a bug from PostgreSQL or not, but when I try a lot of subquery this error will occur.

  • Related