Ordering of window functions with no order specified?

From: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Ordering of window functions with no order specified?
Date: 2017-06-15 04:34:33
Message-ID: CAD3a31WwGBCoPK+KtLBzLdq8o_bJd6n9mha1hgLuGi4jKZBo6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi. If you use a window function and don't specify an order, will the rows
be processed in the same order as the query results?

In this particular case, I'm wondering about row_number(), and whether I
explicitly need to repeat the ordering that's already specified in the
query?

SELECT a,b,c,row_number()
OVER (PARTITION BY a) -- Do I need an ORDER BY c,b here?
FROM foo
ORDER BY c,b

Also, I'm interested in both what if any behavior is guaranteed, and what
gets done in practice. (i.e., a SELECT with no order doesn't have
guarantees, but in practice seems to return the results in the order they
were added to the table. Is it something similar here?)

Thanks!

Ken

--
AGENCY Software
A Free Software data system
By and for non-profits
*http://agency-software.org/ <http://agency-software.org/>*
*https://agency-software.org/demo/client
<https://agency-software.org/demo/client>*
ken(dot)tanzer(at)agency-software(dot)org
(253) 245-3801

Subscribe to the mailing list
<agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
learn more about AGENCY or
follow the discussion.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2017-06-15 05:26:57 Re: Ordering of window functions with no order specified?
Previous Message Andreas Kretschmer 2017-06-15 04:27:53 Re: Repmgr + pgbouncer - Notification of master promotion to application level ...