Thread

Commits

  1. Further fix dumping of views that contain just VALUES(...).

  1. BUG #16119: pg_dump omits columns specification for matviews

    The Post Office <noreply@postgresql.org> — 2019-11-15T22:16:51Z

    The following bug has been logged on the website:
    
    Bug reference:      16119
    Logged by:          Dmitry Telpt
    Email address:      dmitry.telpt@gmail.com
    PostgreSQL version: 9.4.25
    Operating system:   Linux/Docker
    Description:        
    
    Hi there,
    
    We've faced up with an issue how pg_dump exports materialzed views, it
    doesn't export columns declaration that is legal parameter of CREATE DDL
    instruction.
    As I can see from db_dump source, it's intent behaviour and supposed that
    columns declarion will be picked up from query statement when matview is
    created by target instance. However, if matview is 'static' (doesn't have a
    query statement), it sets default column names (column1, column2, etc) that
    breaks all dependent tables/views/matviews, for instance:
    
    postgres=> CREATE MATERIALIZED VIEW test_mv
      (id, alias) AS
      VALUES (1, 5), (2, 6), (3, 17)
    ;
    SELECT 3
    postgres=> \d+ test_mv
                     Materialized view "public.test_mv"
     Column |  Type   | Modifiers | Storage | Stats target | Description 
    --------+---------+-----------+---------+--------------+-------------
     id     | integer |           | plain   |              | 
     alias  | integer |           | plain   |              | 
    View definition:
     VALUES (1,5), (2,6), (3,17);
    
    
    but pg_dump produces the following DDL statement:
    --
    -- Name: test_mv; Type: MATERIALIZED VIEW; Schema: public; Owner: postgres
    --
    
    CREATE MATERIALIZED VIEW public.test_mv AS
     VALUES (1,5), (2,6), (3,17)
      WITH NO DATA;
    
    that leads to the following declaration in target instance:
    postgres=> \d+ test_mv
             Materialized view "public.test_mv"
     Column  |  Type   | Modifiers | Storage | Stats target | Description 
    ---------+---------+-----------+---------+--------------+-------------
     column1 | integer |           | plain   |              | 
     column2 | integer |           | plain   |              | 
    View definition:
     VALUES (1,5), (2,6), (3,17);
    
    the version of engine or db_dump doesn't matter, the same behavior.
    
    it's minor bug, since dump file may be fixed manually before restoring but
    when you don't have access to file (for instance, AWS RDS upgrade
    procedure), it becomes very painful.
    
    Thanks,
    Dmitry
    
    
  2. Re: BUG #16119: pg_dump omits columns specification for matviews

    Tom Lane <tgl@sss.pgh.pa.us> — 2019-11-16T06:05:36Z

    PG Bug reporting form <noreply@postgresql.org> writes:
    > We've faced up with an issue how pg_dump exports materialzed views, it
    > doesn't export columns declaration that is legal parameter of CREATE DDL
    > instruction.
    > As I can see from db_dump source, it's intent behaviour and supposed that
    > columns declarion will be picked up from query statement when matview is
    > created by target instance. However, if matview is 'static' (doesn't have a
    > query statement), it sets default column names (column1, column2, etc) that
    > breaks all dependent tables/views/matviews, for instance:
    
    > postgres=> CREATE MATERIALIZED VIEW test_mv
    >   (id, alias) AS
    >   VALUES (1, 5), (2, 6), (3, 17)
    > ;
    
    Hmm ... I agree this is not good, but this example doesn't seem like
    a matview that anyone would create in practice.  For curiosity's sake,
    would you explain the actual use-case that you hit this in?
    
    			regards, tom lane
    
    
    
    
  3. Re: BUG #16119: pg_dump omits columns specification for matviews

    Tom Lane <tgl@sss.pgh.pa.us> — 2019-11-17T01:02:39Z

    PG Bug reporting form <noreply@postgresql.org> writes:
    > We've faced up with an issue how pg_dump exports materialzed views, it
    > doesn't export columns declaration that is legal parameter of CREATE DDL
    > instruction.
    
    I figured out what was going wrong here and pushed a fix for it.
    I'm still a bit curious about the real use-case, since a materialized
    view made from just a VALUES clause seems a bit pointless.
    
    			regards, tom lane
    
    
    
    
  4. Re: BUG #16119: pg_dump omits columns specification for matviews

    Gmail <dmitry.telpt@gmail.com> — 2019-11-18T19:08:29Z

    Hi Tom,
    
    Sorry for a little delay in response, there was no email access over the weekend =)
    You know, everything that seems to be ugly for developer maybe 'desired' for customer and contrary in real world.
    
    So, in our case, we're not owner or primary user of schema, only consume data that is maintained by another app and there is inter-team agreement that we can ONLY have views in their schema, that's a cause of such 'strange' solution.
    
    Thanks for a fast feedback and great job!
    Just a question, will the fix be back-ported to current supported branches like 9.4/9.5/9.6 or only included in 12?
    
    Thank you again,
    Dmitry
    
    > On Nov 16, 2019, at 5:02 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > 
    > PG Bug reporting form <noreply@postgresql.org> writes:
    >> We've faced up with an issue how pg_dump exports materialzed views, it
    >> doesn't export columns declaration that is legal parameter of CREATE DDL
    >> instruction.
    > 
    > I figured out what was going wrong here and pushed a fix for it.
    > I'm still a bit curious about the real use-case, since a materialized
    > view made from just a VALUES clause seems a bit pointless.
    > 
    >            regards, tom lane
    
    
    
    
  5. Re: BUG #16119: pg_dump omits columns specification for matviews

    Tom Lane <tgl@sss.pgh.pa.us> — 2019-11-19T17:47:31Z

    Gmail <dmitry.telpt@gmail.com> writes:
    > Just a question, will the fix be back-ported to current supported branches like 9.4/9.5/9.6 or only included in 12?
    
    I back-patched it, see
    
    https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=bf2efc55da9a1a33da32fa383db9db2f2c49b2cb
    
    			regards, tom lane
    
    
    
    
  6. Re: BUG #16119: pg_dump omits columns specification for matviews

    Gmail <dmitry.telpt@gmail.com> — 2019-11-19T20:04:00Z

    my apology, didn't notice 'Like the previous patch, back-patch to all supported branches.' in the comment.
    And it seems to have been little bit late with report, so it wasn't included into the current minor update... am I right that next minor update will happen in February?
    
    Thank you,
    Dmitry
    
    > On Nov 19, 2019, at 9:47 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > 
    > I back-patched it, see
    > 
    > https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=bf2efc55da9a1a33da32fa383db9db2f2c49b2cb