pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Abbate <jma@freedomcircle.com>
To: pgsql-bugs@postgresql.org
Subject: Spaces before newlines in view definitions in 9.3
Date: Tue, 10 Sep 2013 17:21:58 -0400
Message-ID: <522F8D76.8010400@freedomcircle.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Example test code:

$ psql pyrseas_testdb
psql (9.3.0)
Type "help" for help.

pyrseas_testdb=# create table t1 (c1 int, c2 text);
CREATE TABLE
pyrseas_testdb=# create view v1 as select * from t1;
CREATE VIEW
pyrseas_testdb=# \d+ v1
                   View "public.v1"
 Column |  Type   | Modifiers | Storage  | Description
--------+---------+-----------+----------+-------------
 c1     | integer |           | plain    |
 c2     | text    |           | extended |
View definition:
 SELECT t1.c1,
    t1.c2
   FROM t1;

It may not be immediately obvious but there is a space after the
"t1.c1," and before the first newline.  In 9.2 and previous releases,
the view definition is:

 SELECT t1.c1, t1.c2
   FROM t1;

If there are more columns, there's an extra space for each except the
last one, e.g., (with _ denoting a trailing space):

 SELECT t2.c1,_
    t2.c2,_
    t2.c3,_
    t2.c4
   FROM t2;

The problem is that the string comes back, e.g., from pg_get_viewdef()
with those extra spaces before the newlines, e.g.,

" SELECT t1.c1, \n    t1.c3 * 2 AS mc3\n   FROM t1;

and YAML has a way displaying a text string nicely so that it can be
recovered when it's read back, but it *doesn't* work if there are
invisible characters such as tabs or spaces before a newline because
obviously one can't tell how many or of what kind they are.

Note: This applies to both views and materialized views.

I believe the reformatting of view text (breaking each column on a
separate line) was done to improve readability but it has the side
effect of making the text unreadable if processed via a YAML utility
such as Pyrseas dbtoyaml (since YAML then quotes the entire string and
even breaks it down further with extra backslashes).

Regards,

Joe


-- 
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 (4+ messages)  latest in thread

Message-ID: <522F8D76.8010400@freedomcircle.com>
Permalink:  ../522F8D76.8010400@freedomcircle.com/
Also on:    postgresql.org/message-id/522F8D76.8010400@freedomcircle.com

 · 

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: jma@freedomcircle.com
  Subject: Re: Spaces before newlines in view definitions in 9.3
  In-Reply-To: <522F8D76.8010400@freedomcircle.com>
  References: <522F8D76.8010400@freedomcircle.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