From: Lele Gaifax <lele@metapensiero.it>
To: pgsql-general@postgresql.org
Subject: Create recursive view schema.name
Date: Tue, 11 Oct 2016 09:36:37 +0200
Message-ID: <871sznz69m.fsf@metapensiero.it> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>
Hi all,
I'm using PG 9.6, learning the "recursive" queries.
I have a working recursive-CTE query, and I tried wrapping it in a view:
reading the documentation I found the "CREATE RECURSIVE VIEW" form, so I tried
it.
It works as far as I use a "simple" name for the view:
CREATE OR REPLACE RECURSIVE VIEW procedure_sites (procedure_id, site_id) AS
SELECT pr.id, pr.site_id
FROM sop.procedures pr
JOIN sop.phases ph on ph.procedure_id = pr.id
UNION ALL
SELECT s.procedure_id, ss.site_id
FROM procedure_sites s
JOIN risk.company_sites ss ON ss.id = s.site_id
WHERE ss.site_id IS NOT NULL;
but I get an error when I create it in a specific schema:
CREATE OR REPLACE RECURSIVE VIEW sop.procedure_sites (procedure_id, site_id) AS
SELECT pr.id, pr.site_id
FROM sop.procedures pr
JOIN sop.phases ph on ph.procedure_id = pr.id
UNION ALL
SELECT s.procedure_id, ss.site_id
FROM sop.procedure_sites s
JOIN risk.company_sites ss ON ss.id = s.site_id
WHERE ss.site_id IS NOT NULL;
ERROR: relation "sop.procedure_sites" does not exist
RIGA 8: JOIN sop.procedure_sites s ON s.site_id = ss.id
^
Am I missing something?
Thanks in advance for any hint,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it | -- Fortunato Depero, 1929.
--
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: lele@metapensiero.it
Subject: Re: Create recursive view schema.name
In-Reply-To: <871sznz69m.fsf@metapensiero.it>
References: <871sznz69m.fsf@metapensiero.it>
* 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