Re: Format Function

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: Format Function
Дата
Msg-id 200302171256.59403.josh@agliodbs.com
обсуждение исходный текст
Ответ на Format Function  ("Yudie" <yudie@axiontech.com>)
Список 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 по дате отправления:

Предыдущее
От: "Yudie"
Дата:
Сообщение: Format Function
Следующее
От: Tomasz Myrta
Дата:
Сообщение: Re: