Re: line CASE statemelnt in query a la Oracle

From: John R Pierce <pierce(at)hogranch(dot)com>
To: Dennis Gearon <gearond(at)sbcglobal(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: line CASE statemelnt in query a la Oracle
Date: 2010-09-09 05:18:00
Message-ID: 4C886E08.1040500@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/08/10 10:05 PM, Dennis Gearon wrote:
> I would like to have a query replace a NULL in a field with a truncated value from one field based on a size passed in?
>
> Basically, I'd like to be able to generate a 'short title' for a record based on either the user's input for a short title, or a turncated 'normal title' at query time.
>
> Would this be very expensive processor timewise?
>
> I might just feed the whole long title in and have the display properties of the browser truncate it.
>
>

shoudl be quite simple with coalesce... say you have a short_title
field that might be null, and long_title is the full title...

SELECT ...., COALESCE(short_title, SUBSTRING(long_title FOR $1)),....

where $1 is your passed in length.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2010-09-09 06:06:37 Re: Dynamically update NEW columns in plpgsql trigger
Previous Message Dennis Gearon 2010-09-09 05:05:42 line CASE statemelnt in query a la Oracle