pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: bernardjech@yahoo.com
To: pgsql-bugs@postgresql.org
Subject: BUG #7869: Expressions in a view for rows that are not part of the view result set are still evaluated
Date: Tue, 12 Feb 2013 16:39:42 +0000
Message-ID: <E1U5ItS-0003HY-NQ@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:      7869
Logged by:          Bernard Jech
Email address:      bernardjech@yahoo.com
PostgreSQL version: 9.2.3
Operating system:   Mac OS X 10.6.8
Description:        

-- Create the tables:

CREATE TABLE netblock (
  id INTEGER,
  ip_address inet NOT NULL
);

CREATE TABLE ipv4 (
  netblock_id integer
);

-- Insert data:

INSERT INTO netblock VALUES(1, '2605:ee00::/32');
INSERT INTO netblock VALUES(2, '68.67.181.7/26');
INSERT INTO ipv4 VALUES(2);

-- Create the view:

CREATE OR REPLACE VIEW subnet AS
SELECT ipv4.netblock_id AS id,
  set_masklen(n.ip_address, 32) - inet '0.0.0.0' AS cidr_address
FROM ipv4 JOIN netblock n ON ipv4.netblock_id = n.id;

If you select all rows from the view subnet, you get the expected result:

pokus=> select * from subnet;
 id | cidr_address 
----+--------------
  2 |   1145287943
(1 row)

The surprising part comes when you add a WHERE clause to the SELECT
statement to select only this one row:

pokus=> select * from subnet where cidr_address = 1145287943;
ERROR:  cannot subtract inet values of different sizes

This is apparently caused by the IPv6 entry in the netblock table but this
row should be excluded by the inner JOIN in the VIEW definition.



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



Message-ID: <E1U5ItS-0003HY-NQ@wrigleys.postgresql.org>
Permalink:  ../E1U5ItS-0003HY-NQ@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1U5ItS-0003HY-NQ@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: bernardjech@yahoo.com
  Subject: Re: BUG #7869: Expressions in a view for rows that are not part of the view result set are still evaluated
  In-Reply-To: <E1U5ItS-0003HY-NQ@wrigleys.postgresql.org>
  References: <E1U5ItS-0003HY-NQ@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