Re: Format Function - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Format Function
Date
Msg-id 200302171256.59403.josh@agliodbs.com
Whole thread Raw
In response to Format Function  ("Yudie" <yudie@axiontech.com>)
List pgsql-sql
Yudie,

> Is there any default function for formating string in postgre sql?
> for instance:
> Format('123ABCDE', '####-###-###') => '12-3AB-CDE'
>
> The closest function I know is the to_char() function but it only works for
numbers

No, there isn't.  You could write one, though.  For example, you could write:

(7.3 syntax)

CREATE FUNCTION yudie_format(text) RETURNS text AS
'SELECT SUBSTR($1, 1, 4) || ''-'' || SUBSTR($1,5,3) || ''-'' ||
SUBSTR($1,9,4);
' LANGUAGE SQL IMMUTABLE STRICT;

As a simple formatting function.

For that matter, it would be the work of a weekend for someone to write a
function in PL/Perl which would take a format mask and apply it to any text
string.

--
-Josh BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: "Yudie"
Date:
Subject: Format Function
Next
From: Tomasz Myrta
Date:
Subject: Re: