pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Larry Rosenman <ler@lerctr.org>
To: pgsql-sql@postgresql.org
Subject: Messy Casts, Is there a better way?
Date: 15 Oct 2002 05:16:19 -0500
Message-ID: <1034676979.436.1.camel@lerlaptop.lerctr.org> (raw)

I have a table with the following, in part:

contract_start date
contract_term  int (term in MONTHS)

I want to calculate the contract end date.  I came up with:
CREATE FUNCTION "get_contract_end" (integer) RETURNS date AS 'SELECT
cast(contract_start + cast(cast(contract_term as text) || '' month'' as
interval) as date)
FROM circuit
    WHERE internal_id = $1;' LANGUAGE 'sql';


Is there a better way? 



-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749




view thread (6+ messages)  latest in thread

Message-ID: <1034676979.436.1.camel@lerlaptop.lerctr.org>
Permalink:  ../1034676979.436.1.camel@lerlaptop.lerctr.org/
Also on:    postgresql.org/message-id/1034676979.436.1.camel@lerlaptop.lerctr.org

 · 

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: ler@lerctr.org
  Subject: Re: Messy Casts, Is there a better way?
  In-Reply-To: <1034676979.436.1.camel@lerlaptop.lerctr.org>

* 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