pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Flo <fluancefg@gmail.com>
Cc: pgsql-bugs@postgreSQL.org
Subject: Re: Can't restore view with pg_restore
Date: Mon, 29 May 2017 14:53:29 -0400
Message-ID: <27471.1496084009@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPW7RP=mvCOxb=K2cnUgdqmRbnpdz4EX_0hZ+djDyorJ-5VfUQ@mail.gmail.com>
References: <CAPW7RP=YgN+sa_TV2OvQ5404bJ9vA9_YAOd7upJNiNLbtg4qvw@mail.gmail.com>
	<2329.1495640378@sss.pgh.pa.us>
	<CAPW7RP=mvCOxb=K2cnUgdqmRbnpdz4EX_0hZ+djDyorJ-5VfUQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

[ please keep the list cc'd for the archives' sake ]

Flo <fluancefg@gmail.com> writes:
> Very interesting point. I have done a pg_dump -s and I've found in the text
> file that all the views are dumped with a CREATE VIEW command, but not that
> one.

This doesn't seem like it could be all of the commands affecting
bmv_visits_list, because nothing you've shown here could result in
creation of a trigger on bmv_visits_list before the rule is created.

> CREATE RULE "_RETURN" AS
>     ON SELECT TO bmv_visits_list DO INSTEAD  SELECT patient.firstname,
>     patient.lastname,
>     patient.birthdate,
>     company.code,
>     jsonb_agg(jsonb_build_object('nb', v.nb, 'admissiondt', v.admitdt,
> 'patientroom', v.patientroom)) AS visits
>     ...
>   GROUP BY patient.id, company.code;

> Does it have anything to do with the jsonb data type, because it is the
> only view that uses that ?

No.  I think the reason the view is getting dumped like this is the
incomplete GROUP BY spec.  To make that SELECT legal, patient.id must
be a primary key (or at least unique), which means that the pkey or
unique index must be created before we can issue the command.  pg_dump
doesn't want to build indexes until after the data is loaded, so it
has to split creation of this view into creation of a shell view (before
data load) and replacement of the shell with the real view definition
(after data load and index creation).

It might help to think of the CREATE TABLE as being CREATE VIEW with
a dummy view definition and then the CREATE RULE as being like CREATE
OR REPLACE VIEW with the real definition.  The fact that these commands
are spelled the way they are is a historical accident, which we might
or might not get around to fixing someday.

This gets us no closer to understanding your failure though.  Please
take a closer look for other commands mentioning bmv_visits_list before
the CREATE RULE.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (7+ messages)  latest in thread

Message-ID: <27471.1496084009@sss.pgh.pa.us>
Permalink:  ../27471.1496084009@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27471.1496084009@sss.pgh.pa.us

 · 

reply

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fluancefg@gmail.com
  Subject: Re: Can't restore view with pg_restore
  In-Reply-To: <27471.1496084009@sss.pgh.pa.us>
  References: <CAPW7RP=YgN+sa_TV2OvQ5404bJ9vA9_YAOd7upJNiNLbtg4qvw@mail.gmail.com> <2329.1495640378@sss.pgh.pa.us> <CAPW7RP=mvCOxb=K2cnUgdqmRbnpdz4EX_0hZ+djDyorJ-5VfUQ@mail.gmail.com> <27471.1496084009@sss.pgh.pa.us>

* 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