From: Vik Fearing <vik.fearing@dalibo.com>
To: Jeff Janes <jeff.janes@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Easiest way to compare the results of two queries row by row and column by column
Date: Fri, 21 Jun 2013 08:46:23 +0200
Message-ID: <51C3F6BF.2060806@dalibo.com> (raw)
In-Reply-To: <CAMkU=1wRQ6tD_rYEcH3icWgsf5t2SEe-sPOV2+98BTyktQq3rA@mail.gmail.com>
References: <1371766705.15253.44.camel@localhost.localdomain>
<CAMkU=1wRQ6tD_rYEcH3icWgsf5t2SEe-sPOV2+98BTyktQq3rA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>
On 06/21/2013 01:07 AM, Jeff Janes wrote:
> On Thu, Jun 20, 2013 at 3:18 PM, Jason Long
> <mailing.lists@octgsoftware.com
> <mailto:mailing.lists@octgsoftware.com>> wrote:
>
> Can someone suggest the easiest way to compare the results from two
> queries to make sure they are identical?
>
> I am rewriting a large number of views and I want to make sure that
> nothing is changes in the results.
>
> Something like
>
> select compare_results('select * from v_old', 'select * from v_new');
>
>
> I'd run:
>
> select * from v_old
> except
> select * from v_new ;
>
> And then
>
> select * from v_new
> except
> select * from v_old ;
>
> Both should return no rows.
This is my solution as well.
> However, if the queries can contain duplicate rows this will not
> detect differences in the number of times a row is replicated, i.e. if
> one query has a row 2 times and the other has it 3 times. If you need
> to detect such cases, I'd probably \copy out each query to a file,
> then use system tools to sort and diff the files.
No need, just use EXCEPT ALL.
Basically, the following query should return nothing:
(TABLE v_old EXCEPT ALL TABLE v_new)
UNION ALL
(TABLE v_new EXCEPT ALL TABLE v_old);
--
Vik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: vik.fearing@dalibo.com, jeff.janes@gmail.com
Subject: Re: Easiest way to compare the results of two queries row by row and column by column
In-Reply-To: <51C3F6BF.2060806@dalibo.com>
References: <1371766705.15253.44.camel@localhost.localdomain> <CAMkU=1wRQ6tD_rYEcH3icWgsf5t2SEe-sPOV2+98BTyktQq3rA@mail.gmail.com> <51C3F6BF.2060806@dalibo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox