Re: How to compare the results of two queries?

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Juan Daniel Santana Rodés <jdsantana(at)estudiantes(dot)uci(dot)cu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to compare the results of two queries?
Date: 2013-09-17 15:17:26
Message-ID: 52387286.1030402@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 17/09/2013 15:59, Juan Daniel Santana Rodés wrote:
> I am developing a task in which I need to know how to compare the
> results of two queries ...
> I thought about creating a procedure which both queries received by
> parameters respectively. Then somehow able to run queries and return if
> both have the same result. As a feature of the problem, both queries are
> selection.
> Here I leave a piece of code I want to do.
>
> create or replace function compare(sql1 character varying, sql2
> character varying) returns boolean as
> $body$
> Declare
> Begin
> --here in some way to run both queries and then compare
> End;
> $body$
> language 'plpgsql';
>
> I've been studying and I found that there EXECUTE but to use it, first
> you should have used PREPARE, and in this case the values ​​of the

EXECUTE in pl/pgsql is different to EXECUTE in ordinary SQL; it's used
for executing queries constructed on-the-fly as strings. You don't need
to do a PREPARE before EXECUTE in a pl/pgsql function.

Here's the relevant place in the docs for this form of EXECUTE:

http://www.postgresql.org/docs/9.3/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Igor Neyman 2013-09-17 15:27:06 Re: How to compare the results of two queries?
Previous Message Juan Daniel Santana Rodés 2013-09-17 14:59:43 How to compare the results of two queries?