From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Michael Richards <miker@scifair.acadiau.ca>
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Re: [HACKERS] Counting bool flags in a complex query
Date: Mon, 19 Jul 1999 15:11:26 +0300
Message-ID: <l03130303b3b8c4d43b74@[147.233.159.109]> (raw)
In-Reply-To: <Pine.BSF.4.10.9907160447220.38362-100000@scifair.acadiau.ca>
References: <6419.932051230@sss.pgh.pa.us>
At 11:37 +0300 on 16/07/1999, Michael Richards wrote:
> My folder numbers are: negative numbers are system folders such as New
> mail, trash, drafts and sentmail. I wanted to order the tuples so that the
> folderids were sorted from -1 to -4, then 1 to x. This way the system
> folders would always appear first in the list.
>
> This may not be valid SQL, as none of my books mention it. Is it possible
> to order by an expression?
>
> Here are some examples which some some odd behaviour. My suspected bug
> findings are at the end:
I think the problem results from using non-standard constructs such as
order by expression, and indeed ordering by columns that don't appear in
the select list.
If you want to do the best by yourself, put the expression by which you
order in the select list. A simple example would be:
Instead of:
SELECT f1, min( f2 ), max ( f3 )
GROUP BY f1
ORDER BY expr( f1 );
Use:
SELECT expr( f1 ) AS ordcol, f1, min( f2 ), max( f3 )
GROUP BY ordcol, f1
ORDER BY ordcol;
What is the difference? The difference is that now GROUP BY (which also
does internal sorting) knows about that expression and considers it. Since
ordcol is the same for each value of f1, this should not change the groups.
This simply makes sure all parts of the query are aware of what is being
done around them. This is also the standard, as far as I recall.
What's the problem? You have a column in the output that you didn't really
want. But hey, why should that bother you? If you're reading it through
some frontend, simply have it ignore the first column that returns.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
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-sql@postgresql.org
Cc: herouth@oumail.openu.ac.il, miker@scifair.acadiau.ca
Subject: Re: [SQL] Re: [HACKERS] Counting bool flags in a complex query
In-Reply-To: <l03130303b3b8c4d43b74@[147.233.159.109]>
References: <6419.932051230@sss.pgh.pa.us> <l03130303b3b8c4d43b74@[147.233.159.109]>
* 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