I want an output like this:
obid | sid_count
1 | 3
2 | 2
3 | 4
The obid is on custdata table and sid_count is get from identifier table.
The sample data is:
custdata
obid
1
2
3
identifier
obid | type
1 | SID
1 | SID
1 | XID
1 | SID
2 | SID
2 | SID
3 | SID
3 | SID
3 | XID
3 | SID
3 | SID
I try to run this query:
select custdata.obid,
count (identifier.obid) filter (where identifier.type = 'SID') as sid_count
from myschema.custdata, myschema.identifier group by custdata.obid
it took about an hour but got an error:
[53100] ERROR: could not write block 37583345 of temporary file: No space left on device
The custdata is about 65 million records. The identifier is about 250 million records.
How to overcome this problem? Why the database need to write to disk? or do i need to rewrite my query? because i can't add more space to the disk.
Thanks.