Messy Casts, Is there a better way? - Mailing list pgsql-sql

From Larry Rosenman
Subject Messy Casts, Is there a better way?
Date
Msg-id 1034676979.436.1.camel@lerlaptop.lerctr.org
Whole thread Raw
Responses Re: Messy Casts, Is there a better way?
Re: Messy Casts, Is there a better way?
List pgsql-sql
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



pgsql-sql by date:

Previous
From: "Peter Galbavy"
Date:
Subject: Re: IGNORE ME how do i insert an empty string ?
Next
From: Domoszlai László
Date:
Subject: set difference