pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Barrett <anon000000@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: syntax for using function parameter in to_char
Date: Fri, 1 Feb 2002 11:57:03 -0600
Message-ID: <a3ektg$1ofq$1@news.tht.net> (raw)

I am trying to write a function that will take a big int as a paramter and 
return a formatted date string.  The dates in the system I am using are all 
stored as bigint values ( based Java EPOCH ) to I need this function to 
make some sense of the date.

Here is my code:

CREATE FUNCTION java_date( bigint ) RETURNS text AS '
    select to_char(\'epoch\'::datetime + \'$1 seconds\'::interval, 
\'dd/mm/yyyy hh:mi\') as RESULT
  '
  LANGUAGE 'sql';


The problem seems to be that the $1 in the to_char function is not getting 
parsed with the actual value of $1.

If I execute the following from the command line, I get the expected 
response:

=> select to_char('epoch'::datetime + '1012437127 seconds'::interval, 
'dd/mm/yyyy hh:mi');

     to_char
------------------
 30/01/2002 06:32
(1 row)

All I am trying to do is move the functionality of this SQL statement to a 
function so I can easily reuse it.

Any help would be appreciated.

Kevin Barrett





view thread (2+ messages)  latest in thread

Message-ID: <a3ektg$1ofq$1@news.tht.net>
Permalink:  ../a3ektg$1ofq$1@news.tht.net/
Also on:    postgresql.org/message-id/a3ektg$1ofq$1@news.tht.net

 · 

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: anon000000@hotmail.com
  Subject: Re: syntax for using function parameter in to_char
  In-Reply-To: <a3ektg$1ofq$1@news.tht.net>

* 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