I have the following query which runs perfectly well on both Oracle and SQL Server 2008 however it doesn’t seem to run on PostgreSQL. The query is intended to return a count of records that match the given criteria. Can someone explain the reason for this and also offer a solution to how this query can be modified to allow it to produce the expected result.
Query:
select count(*)
from tma_notices
where TNOT_NOTICE_TYPE ='0400'
and TNOT_NOTICE_STATUS = 'OK'
and tnot_notice_id >=
(
select NOTICE_NUM_AT_MIDNIGHT
from RWOL_COUNTER_QUERY_TYPE
where QUERY_TYPE = 'START_NOTICES_TODAY'
and USER_NAME = 'PUBLIC'
)
UPDATE: This error was caused by unforeseen duplicate records in the PostgreSQL database. Where the duplicates came from needs to be investigated.
It’s pretty clear that the subquery could return a set of rows and the condition
tnot_notice_id >=isn’t valid if compared with a set of rows and not with only a single value.Are you sure that exist a unique record that satisfy your where conditions?
If you want to avoid that behaviour, I suggest you to use
tnot_notice_id >= ALL ( subquery )