pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: balazs@obiserver.hu
To: pgsql-bugs@postgresql.org
Subject: BUG #8698: cast and view
Date: Mon, 23 Dec 2013 18:43:37 +0000
Message-ID: <E1VvATZ-0004mC-B4@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      8698
Logged by:          Balazs Peter Odor
Email address:      balazs@obiserver.hu
PostgreSQL version: 9.3.2
Operating system:   Debian Linux
Description:        

CREATE SCHEMA test;
CREATE TYPE test.customcompositetype AS (
  x text,
  y text
);
CREATE TABLE test.customtable (
  compositetype test.customcompositetype
);
INSERT INTO test.customtable (compositetype)
  VALUES ('(x1,y1)'), ('(x2,y2)');


SELECT * FROM test.customtable;
 compositetype
---------------
 (x1,y1)
 (x2,y2)
(2 rows)


CREATE VIEW test.customview as
  SELECT compositetype, compositetype::text AS compositetype_text
  FROM test.customtable;


SELECT * FROM test.customview;
 compositetype | compositetype_text
---------------+--------------------
 (x1,y1)       | (x1,y1)
 (x2,y2)       | (x2,y2)
(2 rows)


Ok, lets create a cast to customcompositetype to text:


CREATE FUNCTION test.customcompositetype_text(test.customcompositetype)
  RETURNS text AS
$$SELECT ($1).x || ' ' || ($1).y;$$
  IMMUTABLE
  LANGUAGE SQL
;
CREATE CAST (test.customcompositetype AS text)
  WITH FUNCTION test.customcompositetype_text(test.customcompositetype);


SELECT * FROM test.customview;
 compositetype | compositetype_text
---------------+--------------------
 (x1,y1)       | (x1,y1)
 (x2,y2)       | (x2,y2)
(2 rows)


What?? :(


Refresh the view:


CREATE OR REPLACE VIEW test.customview as
  SELECT compositetype, compositetype::text AS compositetype_text
  FROM test.customtable;


SELECT * FROM test.customview;
 compositetype | compositetype_text
---------------+--------------------
 (x1,y1)       | x1 y1
 (x2,y2)       | x2 y2
(2 rows)


Whats wrong? Why need recreate the view??



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

Message-ID: <E1VvATZ-0004mC-B4@wrigleys.postgresql.org>
Permalink:  ../E1VvATZ-0004mC-B4@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1VvATZ-0004mC-B4@wrigleys.postgresql.org

 · 

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: balazs@obiserver.hu
  Subject: Re: BUG #8698: cast and view
  In-Reply-To: <E1VvATZ-0004mC-B4@wrigleys.postgresql.org>
  References: <E1VvATZ-0004mC-B4@wrigleys.postgresql.org>

* 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