pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14177: ARRAYs in VIEWs are inconsistently cast
2+ messages / 2 participants
[nested] [flat]

* BUG #14177: ARRAYs in VIEWs are inconsistently cast
@ 2016-06-03 22:17 taylor.reece@zuerchertech.com
  2016-06-06 14:44 ` Re: BUG #14177: ARRAYs in VIEWs are inconsistently cast Amit Langote <amitlangote09@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: taylor.reece@zuerchertech.com @ 2016-06-03 22:17 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14177
Logged by:          Taylor Reece
Email address:      taylor.reece@zuerchertech.com
PostgreSQL version: 9.5.3
Operating system:   Ubuntu Server 14.04 and 16.04
Description:        

This is an issue I've noticed throughout 9.3.*, and now in 9.5.*.  If I
define a VIEW ('v1', below), and then use that VIEW's compiled definition to
create a second VIEW ('v2', below), the two VIEWs have different compiled
definitions.

I first discovered this inconsistency when I ran pg_dump on a database and
restored the backup to another server.  The servers' schemas were not
completely consistent with one another, despite running identical versions
of psql.

I recognize that the differences in VIEW definitions are cosmetic -- they're
functionally equivalent.  One casts an ARRAY of VARCHAR to ::text[] while
the other casts the elements individually to VARCHAR and then TEXT. In an
effort to keep database schema completely identical, though, it would be
nice if a pg_dump into a pg_restore resulted in exactly identical schema.

An example of how to replicate the issue follows.  Thank you in advance for
your expertise, and for such an awesome DB product!

-Taylor

...

user@server:/tmp# psql d1
psql (9.5.3)
Type "help" for help.

d1=# CREATE TABLE t (a CHARACTER VARYING);
CREATE TABLE
d1=# CREATE VIEW v1 AS SELECT a FROM t WHERE t.a IN ('b','c');
CREATE VIEW
d1=# \d+ v1
                         View "public.v1"
 Column |       Type        | Modifiers | Storage  | Description 
--------+-------------------+-----------+----------+-------------
 a      | character varying |           | extended | 
View definition:
 SELECT t.a
   FROM t
  WHERE t.a::text = ANY (ARRAY['b'::character varying, 'c'::character
varying]::text[]);

d1=# CREATE VIEW v2 AS  SELECT t.a
d1-#    FROM t
d1-#   WHERE t.a::text = ANY (ARRAY['b'::character varying, 'c'::character
varying]::text[]);
CREATE VIEW
d1=# \d+ v2
                        View "public.v2"
 Column |       Type        | Modifiers | Storage  | Description 
--------+-------------------+-----------+----------+-------------
 a      | character varying |           | extended | 
View definition:
 SELECT t.a
   FROM t
  WHERE t.a::text = ANY (ARRAY['b'::character varying::text, 'c'::character
varying::text]);


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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #14177: ARRAYs in VIEWs are inconsistently cast
  2016-06-03 22:17 BUG #14177: ARRAYs in VIEWs are inconsistently cast taylor.reece@zuerchertech.com
@ 2016-06-06 14:44 ` Amit Langote <amitlangote09@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Amit Langote @ 2016-06-06 14:44 UTC (permalink / raw)
  To: taylor.reece@zuerchertech.com; +Cc: pgsql-bugs

On Sat, Jun 4, 2016 at 7:17 AM,  <taylor.reece@zuerchertech.com> wrote:
> The following bug has been logged on the website:
>
> Bug reference:      14177
> Logged by:          Taylor Reece
> Email address:      taylor.reece@zuerchertech.com
> PostgreSQL version: 9.5.3
> Operating system:   Ubuntu Server 14.04 and 16.04
> Description:
>
> This is an issue I've noticed throughout 9.3.*, and now in 9.5.*.  If I
> define a VIEW ('v1', below), and then use that VIEW's compiled definition to
> create a second VIEW ('v2', below), the two VIEWs have different compiled
> definitions.
>
> I first discovered this inconsistency when I ran pg_dump on a database and
> restored the backup to another server.  The servers' schemas were not
> completely consistent with one another, despite running identical versions
> of psql.
>
> I recognize that the differences in VIEW definitions are cosmetic -- they're
> functionally equivalent.  One casts an ARRAY of VARCHAR to ::text[] while
> the other casts the elements individually to VARCHAR and then TEXT. In an
> effort to keep database schema completely identical, though, it would be
> nice if a pg_dump into a pg_restore resulted in exactly identical schema.
>
> An example of how to replicate the issue follows.  Thank you in advance for
> your expertise, and for such an awesome DB product!
>
> -Taylor
>
> ...
>
> user@server:/tmp# psql d1
> psql (9.5.3)
> Type "help" for help.
>
> d1=# CREATE TABLE t (a CHARACTER VARYING);
> CREATE TABLE
> d1=# CREATE VIEW v1 AS SELECT a FROM t WHERE t.a IN ('b','c');
> CREATE VIEW
> d1=# \d+ v1
>                          View "public.v1"
>  Column |       Type        | Modifiers | Storage  | Description
> --------+-------------------+-----------+----------+-------------
>  a      | character varying |           | extended |
> View definition:
>  SELECT t.a
>    FROM t
>   WHERE t.a::text = ANY (ARRAY['b'::character varying, 'c'::character
> varying]::text[]);
>
> d1=# CREATE VIEW v2 AS  SELECT t.a
> d1-#    FROM t
> d1-#   WHERE t.a::text = ANY (ARRAY['b'::character varying, 'c'::character
> varying]::text[]);
> CREATE VIEW
> d1=# \d+ v2
>                         View "public.v2"
>  Column |       Type        | Modifiers | Storage  | Description
> --------+-------------------+-----------+----------+-------------
>  a      | character varying |           | extended |
> View definition:
>  SELECT t.a
>    FROM t
>   WHERE t.a::text = ANY (ARRAY['b'::character varying::text, 'c'::character
> varying::text]);

Patch to fix this behavior was posted (not applied yet though) a
little while ago:

https://www.postgresql.org/message-id/17675.1459353646%40sss.pgh.pa.us

Thanks,
Amit


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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-06-06 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 22:17 BUG #14177: ARRAYs in VIEWs are inconsistently cast taylor.reece@zuerchertech.com
2016-06-06 14:44 ` Amit Langote <amitlangote09@gmail.com>

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