Re: CASE returning multiple values (was SQL Help)

From: Richard Huxton <dev(at)archonet(dot)com>
To: C F <tacnaboyz(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: CASE returning multiple values (was SQL Help)
Date: 2003-06-02 07:51:52
Message-ID: 200306020851.52868.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Friday 30 May 2003 7:01 pm, C F wrote:
> I was afraid someone was going to ask that :)
> Okay, I'll do my best at explaining where I'm coming from....
[snip long but detailed description I asked for -thanks]

Right - I've done something similar to this before, and I ended up building my
SQL on the fly with something like:

rule_where_cond:
rs | rulename | tblname | colname | test | test_value
----+----------|---------+---------+------+-----------
1 | us-only | city | country | = | USA

Note the "rs" is "rule-set" where all criteria for a specific query have the
same rs value.

rule_sizing_cond:
rs | rulename | tblname | colname | minval | maxval | resultval
----+----------+---------+------------+---------+---------+---------------
1 | cityicon | city | population | 0 | 1000000 | small_dot.jpg
1 | cityicon | city | population | 1000001 |99999999 | large_dot.jpg
1 | showname | city | population | 0 | 1000000 | false
1 | showname | city | population | 1000001 |99999999 | true

This one gains you a lot because you just join to it rather than using CASE
clauses.

rule_select_cols:
rs | rulename | tblname | colname | aliasname
----+----------+---------+-----------+-----------
1 | showname | city | city_name | label1

So you're query will now return the city_name as "label1" but you can get a
flag from the "rule_sizing_cond" to say whether to show it or not.

Now, it depends how complicated your conditions can be as to how complicated
the setup of these tables is and also how complicated the query-builder can
be. However, I have used something similar to build queries myself and it
does provide you with a lot of flexibility.

HTH

--
Richard Huxton

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jonathan Gardner 2003-06-02 13:20:56 Re: SQL problem: bank account
Previous Message listrec 2003-06-02 07:49:55 Re: SQL problem: bank account