Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Taq1R-0000Ky-Su for pgsql-bugs@postgresql.org; Tue, 20 Nov 2012 15:46:01 +0000 Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tapjm-0001Fn-2F for pgsql-bugs@postgresql.org; Tue, 20 Nov 2012 15:27:50 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tapjk-0008AK-Om for pgsql-bugs@postgresql.org; Tue, 20 Nov 2012 15:27:45 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1Tapjk-00074I-EU for pgsql-bugs@postgresql.org; Tue, 20 Nov 2012 15:27:44 +0000 Date: Tue, 20 Nov 2012 15:27:44 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7685: last_value() not consistent throughout window partition To: pgsql-bugs@postgresql.org From: wes@devauld.ca X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201211/164 X-Sequence-Number: 34722 The following bug has been logged on the website: Bug reference: 7685 Logged by: Wes Devauld Email address: wes@devauld.ca PostgreSQL version: 9.2.1 Operating system: Windows 7 Enterprise Description: = -- The last_value(0 window function appears to be changing values -- mid window. An example is detailed below. ----SELECT version(); -- version ------------------------------------------------------------- -- PostgreSQL 9.1.6, compiled by Visual C++ build 1500, 32-bit ------------------------- -- **** DB DUMP **** -- -- PostgreSQL database dump -- -- Dumped from database version 9.1.4 -- Dumped by pg_dump version 9.1.4 -- Started on 2012-11-19 15:01:41 SET statement_timeout =3D 0; SET client_encoding =3D 'UTF8'; SET standard_conforming_strings =3D on; SET check_function_bodies =3D false; SET client_min_messages =3D warning; SET search_path =3D public, pg_catalog; SET default_tablespace =3D ''; SET default_with_oids =3D false; -- -- TOC entry 170 (class 1259 OID 25186) -- Dependencies: 5 -- Name: bug_report; Type: TABLE; Schema: public; Owner: postgres; Tablespace: = -- CREATE TABLE bug_report ( d1 date NOT NULL, d2 date NOT NULL, v real NOT NULL ); ALTER TABLE public.bug_report OWNER TO postgres; -- -- TOC entry 1880 (class 0 OID 25186) -- Dependencies: 170 -- Data for Name: bug_report; Type: TABLE DATA; Schema: public; Owner: postgres -- COPY bug_report (d1, d2, v) FROM stdin; 2012-11-19 2012-11-07 358363 2012-11-18 2012-11-07 358363 2012-11-17 2012-11-07 358363 2012-11-16 2012-11-07 257572 2012-11-15 2012-11-07 257572 2012-11-14 2012-11-07 257572 2012-11-13 2012-11-07 257572 2012-11-12 2012-11-07 257572 2012-11-11 2012-11-07 257572 2012-11-10 2012-11-07 257572 \. -- Completed on 2012-11-19 15:01:42 --**** Description **** select d2, last_value(v) over (partition by d2 order by d1), first_value(v) over (partition by d2 order by d1 desc) from bug_report --Returns: --"2012-11-07";358363;358363 --"2012-11-07";358363;358363 --"2012-11-07";358363;358363 --"2012-11-07";257572;358363 --"2012-11-07";257572;358363 --"2012-11-07";257572;358363 --"2012-11-07";257572;358363 --"2012-11-07";257572;358363 --"2012-11-07";257572;358363 --"2012-11-07";257572;358363 --You can see that the last_value() = --switches in the middle of the --partition for the window function = --when both columns should be = --identical since the first/last = --and asc/desc changes should --cancel each other out. = --Thanks, and good work with the product.