pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: jeff@biccard.com
To: Alvaro Herrera <alvherre@commandprompt.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #5841: rank()+1 fails, 1+rank() succeeds
Date: Tue, 18 Jan 2011 22:19:07 +1100
Message-ID: <20110118221907.u4f00r2ss4kwc8kw@webmail.biccard.com> (raw)
In-Reply-To: <1295276957-sup-5631@alvh.no-ip.org>
References: <201101171034.p0HAYTE7056475@wwwmaster.postgresql.org>
	<1295276957-sup-5631@alvh.no-ip.org>

Thanks for clarifying. I've submitted a note on the interactive  
version of the docs, and attached a small patch to make explicit that  
a window function is followed _immediately_ by an OVER clause, as the  
syntax[1] indicates.

Regards,
Jeff


[1]  
http://www.postgresql.org/docs/current/static/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS

Quoting Alvaro Herrera <alvherre@commandprompt.com>:

> Excerpts from Jeff Turner's message of lun ene 17 07:34:29 -0300 2011:
>
>> test=# select *, rank()+1 over (partition by bar) from t;
>> ERROR:  syntax error at or near "over"
>> LINE 1: select *, rank()+1 over (partition by bar) from t;
>
> The "over" stuff is part of the expression; you can't add the +1 in the
> middle.  This works:
>
> select *, rank() over (partition by bar) + 1 from t;
>
> --
> Álvaro Herrera <alvherre@commandprompt.com>
> The PostgreSQL Company - Command Prompt, Inc.
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
>

Attachments:

doc_window_function.diff (text/x-patch, 1.3K) download diff --git a/doc/src/sgml/advanced.sgml b/doc/src/sgml/advanced.sgml index 784b40a..9cb7173 100644 --- a/doc/src/sgml/advanced.sgml +++ b/doc/src/sgml/advanced.sgml @@ -371,7 +371,7 @@ SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM emps <para> A window function call always contains an <literal>OVER</> clause - following the window function's name and argument(s). This is what + directly following the window function's name and argument(s). This is what syntactically distinguishes it from a regular function or aggregate function. The <literal>OVER</> clause determines exactly how the rows of the query are split up for processing by the window function. diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 04769f1..88345ec 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -11184,8 +11184,8 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab; <para> The built-in window functions are listed in <xref linkend="functions-window-table">. Note that these functions - <emphasis>must</> be invoked using window function syntax; that is an - <literal>OVER</> clause is required. + <emphasis>must</> be invoked using window function syntax; that is must + be immediately followed by an <literal>OVER</> clause. </para> <para>

view thread (4+ messages)  latest in thread

Message-ID: <20110118221907.u4f00r2ss4kwc8kw@webmail.biccard.com>
Permalink:  ../20110118221907.u4f00r2ss4kwc8kw@webmail.biccard.com/
Also on:    postgresql.org/message-id/20110118221907.u4f00r2ss4kwc8kw@webmail.biccard.com

 ·  · 

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: jeff@biccard.com, alvherre@commandprompt.com
  Subject: Re: BUG #5841: rank()+1 fails, 1+rank() succeeds
  In-Reply-To: <20110118221907.u4f00r2ss4kwc8kw@webmail.biccard.com>
  References: <201101171034.p0HAYTE7056475@wwwmaster.postgresql.org> <1295276957-sup-5631@alvh.no-ip.org> <20110118221907.u4f00r2ss4kwc8kw@webmail.biccard.com>

* 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