473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Controlling order of evaluation?

I have an srf sql function "annual_report(<year>)" that
as 14 columns, a category, 12 month numeric columns, and a total
numeric column.

The function finds monthly totals for each category (which is the
target of "order by")
and the grand total for the specified year.

I have another sql function annual_profit_loss(<year>) that summarizes
the total
for each month and the grand total for each year. ( There is a text
column that
serves a label.) It generates a summary for the annual_report function
in essence.

I have hoped that

select * from annual_report(2003)
union
select * from annual_profit_loss(2003)

would print the last select last ;( but it inserts the last selection
alphabetically into the rows of the annual_report depending on the label
field... I suppose I could use a label "zzGrand Totals", but that just
does not look right.

Is there any way I can force the last select to appear last?

Jerry

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #1
2 1762
On Wed, 29 Sep 2004 08:16 am, Jerry LeVan wrote:
I have an srf sql function "annual_report(<year>)" that
as 14 columns, a category, 12 month numeric columns, and a total
numeric column.

The function finds monthly totals for each category (which is the
target of "order by")
and the grand total for the specified year.

I have another sql function annual_profit_loss(<year>) that summarizes
the total
for each month and the grand total for each year. ( There is a text
column that
serves a label.) It generates a summary for the annual_report function
in essence.

I have hoped that

select * from annual_report(2003)
union
select * from annual_profit_loss(2003) Order by title_column = 'Grand Total', month

that will put all rows not containing grand total at the top, sorted by month.
Then grand total's sorted by month. something like that.
would print the last select last ;( but it inserts the last selection
alphabetically into the rows of the annual_report depending on the label
field... I suppose I could use a label "zzGrand Totals", but that just
does not look right.

Is there any way I can force the last select to appear last?

Jerry

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2
Jerry LeVan wrote:
I have hoped that

select * from annual_report(2003)
union
select * from annual_profit_loss(2003)

would print the last select last ;( but it inserts the last selection
alphabetically into the rows of the annual_report depending on the label
field... I suppose I could use a label "zzGrand Totals", but that just
does not look right.
I guess that it's the UNION operator that needs to elimiate duplicate rows
by definition and therefore does sorting to do this. From your
description it seems that you could use UNION ALL instead which might
work ok for you.
Is there any way I can force the last select to appear last?

AFAIK the only sure way is to use ORDER BY if you have
some suitable column or can make one up. Usually using expressions
one can do pretty complicated stuff but it seems that in case of
UNION only select list items are allowed in ORDER BY. But then again you
can do it as subselect and then ....

select a from (
select a,b from ...
union all
select a,b from ...
) u
order by case when b='Last' then 'zzzz' else b end;

Andre

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
8
by: der | last post by:
Hello all, I've a question about order of evaluations in expressions that have && and || operators in them. The question is: will the evalution go left-to-right, no matter what -- even if the...
4
by: Frank Wallingford | last post by:
Note: For those with instant reactions, this is NOT the common "why is i = i++ not defined?" question. Please read on. I came across an interesting question when talking with my colleagues....
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
11
by: Pietro Cerutti | last post by:
Hi group, here I come with a question which is quite simple per se, but for which I can't find an answer. Does the C standard guarantee that inside an expression such as (x && y) "y" is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.