| From: | Josh Berkus <josh(at)agliodbs(dot)com> |
|---|---|
| To: | "Yudie" <yudie(at)axiontech(dot)com>, <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: Format Function |
| Date: | 2003-02-17 20:56:59 |
| Message-ID: | 200302171256.59403.josh@agliodbs.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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 Berkus
Aglio Database Solutions
San Francisco
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomasz Myrta | 2003-02-17 21:01:05 | Re: |
| Previous Message | Yudie | 2003-02-17 20:56:01 | Format Function |