Re: Display of text fields

From: Richard Huxton <dev(at)archonet(dot)com>
To: nasr(dot)laili(at)tin(dot)it
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Display of text fields
Date: 2004-09-09 13:20:38
Message-ID: 414058A6.1060207@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ennio-Sr wrote:
>
> Further to my message of 3rd inst.
> Following your suggestion and after reading some documents, I created
> this sql script:
>
> -----
> SELECT scheda_ltr,
> case scheda_ltr
> when 'T' then
> select * from bib_lt;
> else
> 'autore, titolo, editore from bib_lt;'
> end
> FROM bib_lt;
> -----
> but the result is not what I was after: I get a list with either label
> according to scheda_ltr being 'T' or not!
> Is there any way, once the case is spotted, to obtain execution of the
> query relating to that case, instead of just showing the label?
> Of course I tried without the quotes obtaining parser error.

Ah - looks like I misunderstood what you were trying to do. There is no
way to have a single query return rows with different numbers of columns
- each row must be the same.

You'd have to do something like one of the following (substitute
my_memo_column with whatever your memo field was called).

SELECT
scheda_ltr,
autore,
titolo,
editore,
CASE
WHEN scheda_ltr = 'T' THEN my_memo_column
ELSE 'n/a'
END AS my_memo_column
FROM
bib_lt;

or...

SELECT
scheda_ltr,
CASE
WHEN scheda_ltr='T' THEN autore || ' / ' || titolo || ' / ' || editore
ELSE my_memo_column
END AS merged_columns
FROM
bib_lt;

HTH
--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gaetano Mendola 2004-09-09 13:33:21 Re: postgresql hanging (blocking) with smp kernel
Previous Message Ben Trewern 2004-09-09 12:59:50 pg_dump/pg_dumpall do not correctly dump search_path