Menu

#12 check for equality queries, that can have duplicate rows

Open
nobody
None
Medium
[none]
2014-12-20
2014-11-05
No

I need to compare equality of two results of queries. I can't use utAssert.eqquery because results can have duplicate rows. Real example is a table with primary key, which i have to exclude from check, because values for primary key are generated from sequence.

Test package ut_utassert_eqquery.sql illustrate the problem. Tests not equal sets with duplicate rows in second set and not equal sets with duplicate rows in first set should fail, but they pass.

I implemented a method eqqueryEx which uses a query like below to check equality:

SELECT a,b,c,
       COUNT(srс1) cnt1,
       COUNT(src2) cnt2
  FROM 
    (
      SELECT a, b, c,
             1 srс1,
             to_number(NULL) src2
        FROM tab1
      UNION ALL
      SELECT a, b, c,
             to_number(NULL) srс1,
             1 src2
        FROM tab2
    )
 GROUP BY a,b,c
 HAVING  COUNT(srс1) <> COUNT(src2)

Test package ut_utassert_eqqueryEx.sql has the same tests which pass/fail as expected.

Attachements:
- patch.patch - patch for my changes
- ut_utassert_eqquery.sql - tests for eqquery
- ut_utassert_eqqueryEx.sql - tests for eqqueryEx

PS. I understand, that usually table should have unique constraints besides primary key, but this is not always the case.

3 Attachments

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.