Question on the right way to think about order by

Started by Paula Kirschalmost 8 years ago2 messagesgeneral
Jump to latest
#1Paula Kirsch
pl.kirsch@gmail.com

When I think about using order by in a select statement, e.g.

select id, name, price from stuff order by name;

I think of order by as an operator sorting data returned by the select
statement.

When I think about order by in an aggregate statement, e.g.

select string_agg(product, ' | ' order by product) from products;

is it correct to think of order by as a parameter passed to string_agg?

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Paula Kirsch (#1)
Re: Question on the right way to think about order by

On Tuesday, July 3, 2018, Paula Kirsch <pl.kirsch@gmail.com> wrote:

When I think about order by in an aggregate statement, e.g.

select string_agg(product, ' | ' order by product) from products;

is it correct to think of order by as a parameter passed to string_agg?

For a user it's simply the order that rows are passed into the function.
If the state transition aspect retains order this is how you can control
it. The function itself doesn't really ever see the parameter, it just
sees ordered data.

David J.