From: David Johnston <polobo@yahoo.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: Thu, 20 Jun 2013 16:05:20 -0700 (PDT)
Message-ID: <1371769520256-5760215.post@n5.nabble.com> (raw)
In-Reply-To: <1371766705.15253.44.camel@localhost.localdomain>
References: <1371766705.15253.44.camel@localhost.localdomain>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>
Jason Long-2 wrote
> Can someone suggest the easiest way to compare the results from two
> queries to make sure they are identical?
First thing that comes to mind:
WITH
before_qry (col1, col2, col3) AS ( VALUES (1,1,1),(2,2,2),(3,3,3) )
, after_qry (col1, col2, col3) AS ( VALUES (1,1,1),(2,2,2),(3,3,3) )
, before_array AS (SELECT array_agg(before_qry) AS before_agg_array
FROM before_qry)
, after_array AS (SELECT array_agg(before_qry) AS after_agg_array FROM
before_qry)
SELECT *, before_agg_array = after_agg_array
FROM before_array CROSS JOIN after_array
Basically turn the resultsets into arrays (of composites) and then see if
the arrays are the same. This has issues with respect to column names and
comparable datatypes (i.e., if one column is bigint and the other is integer
they still compare equally).
One thought would to only allow a view name (and possibly, separately, the
ORDER BY clause). Catalog lookups can be used to check for identical view
output types.
No idea of something like this exists and is readily available.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Easiest-way-to-compare-the-results-of-two-queries-row-by-row...
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
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: polobo@yahoo.com
Subject: Re: Easiest way to compare the results of two queries row by row and column by column
In-Reply-To: <1371769520256-5760215.post@n5.nabble.com>
References: <1371766705.15253.44.camel@localhost.localdomain> <1371769520256-5760215.post@n5.nabble.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