pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Keith Worthington <KeithW@NarrowPathInc.com>
To: pgsql-sql@postgresql.org
Subject: dow question
Date: Wed, 07 Dec 2005 21:03:05 -0500
Message-ID: <43979459.9020500@NarrowPathInc.com> (raw)

Hi All,

I am working on a query which in part is

CASE
    WHEN extract(dow from tbl_detail.ship_by_date) = 0
       THEN 'Sunday ' || tbl_detail.ship_by_date::text
    WHEN extract(dow from tbl_detail.ship_by_date) = 1
       THEN 'Monday ' || tbl_detail.ship_by_date::text
    WHEN extract(dow from tbl_detail.ship_by_date) = 2
       THEN 'Tuesday ' || tbl_detail.ship_by_date::text
    WHEN extract(dow from tbl_detail.ship_by_date) = 3
       THEN 'Wednesday ' || tbl_detail.ship_by_date::text
    WHEN extract(dow from tbl_detail.ship_by_date) = 4
       THEN 'Thursday ' || tbl_detail.ship_by_date::text
    WHEN extract(dow from tbl_detail.ship_by_date) = 5
       THEN 'Friday ' || tbl_detail.ship_by_date::text
    WHEN extract(dow from tbl_detail.ship_by_date) = 6
       THEN 'Saturday ' || tbl_detail.ship_by_date::text
END AS sort_by_string

Is there a better way to do this?  The CASE seems inefficient and wordy 
but perhaps not.

I was hoping for

day_name(tbl_detail.ship_by_date) || tbl_detail.ship_by_date::text AS 
sort_by_string

but AFAIK day_name(date) or something like it is merely my fantasy. ;-)

-- 
Kind Regards,
Keith



view thread (3+ messages)  latest in thread

Message-ID: <43979459.9020500@NarrowPathInc.com>
Permalink:  ../43979459.9020500@NarrowPathInc.com/
Also on:    postgresql.org/message-id/43979459.9020500@NarrowPathInc.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: KeithW@NarrowPathInc.com
  Subject: Re: dow question
  In-Reply-To: <43979459.9020500@NarrowPathInc.com>

* 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