Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F342B475DA3 for ; Tue, 15 Oct 2002 06:16:18 -0400 (EDT) Received: from lerlaptop.lerctr.org (lerlaptop.lerctr.org [207.158.72.14]) by postgresql.org (Postfix) with ESMTP id 50C9C475AE4 for ; Tue, 15 Oct 2002 06:16:18 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by lerlaptop.lerctr.org (8.12.6/8.12.5) with ESMTP id g9FAGJPM000843 for ; Tue, 15 Oct 2002 05:16:19 -0500 (CDT) (envelope-from ler@lerctr.org) Subject: Messy Casts, Is there a better way? From: Larry Rosenman To: pgsql-sql@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 15 Oct 2002 05:16:19 -0500 Message-Id: <1034676979.436.1.camel@lerlaptop.lerctr.org> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-milter (http://amavis.org/) X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/159 X-Sequence-Number: 9876 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