Improper processing of random values in sub-queries - Mailing list pgsql-bugs

From David Newall
Subject Improper processing of random values in sub-queries
Date
Msg-id 1088781410.3205.386.camel@localhost.localdomain
Whole thread Raw
Responses Re: Improper processing of random values in sub-queries
List pgsql-bugs
PostgreSQL version:  7.4.3 (RPMs from ftp.au.postgresql.org)

Operating Sysem: Fedora Core 1


GIVEN

CREATE TABLE data (i integer);

AND

SELECT count(*), min(i), max(i) FROM data;
 count | min | max
-------+-----+-----
  1340 |   3 |  20
(1 row)

(Actual data attached as data.dmp)


NOW CONSIDER the following query, executed using psql:

SELECT i, j from (
  SELECT i, ((i + 18 * random())::integer % 20 + 1) AS j FROM data
) foo WHERE j = 15;

Column j should be constant (15) for all rows.  In fact I get the
following output:

 i  | j
----+----
  8 |  2
  8 |  1
  8 | 13
  8 |  5
  8 |  5
  9 | 19
  9 |  1
 10 |  8
 10 |  4
 11 |  5
 12 |  9
 19 | 10
  3 | 15
  3 | 16
  3 |  5
  3 | 18
  3 | 11
  3 | 10
  3 |  7
  3 | 13
  3 | 10
  3 | 18
  3 |  2
      .
      .
      .
(74 rows)

The same problem occurs for any constraint of j in the range 1..20

Attachment

pgsql-bugs by date:

Previous
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1189: unbounded string copy in postmaster
Next
From: "Dario V. Fassi"
Date:
Subject: Re: [JDBC] Error in DatabaseMetaData.getColumns() with Views