text formatting in a query, a la sprintf

Поиск
Список
Период
Сортировка
От Reece Hart
Тема text formatting in a query, a la sprintf
Дата
Msg-id 1156021157.4158.496.camel@tallac.gene.com
обсуждение исходный текст
Ответы Re: text formatting in a query, a la sprintf  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-general
I often desire text and number formatting that's not available with functions like to_char. I'd really like to have functionality akin to sprintf, such as:

$ select no_hits,term,sprintf('http://google.com?q=%s',replace(queryterm,' ','+')) as url from queries;
$ select event,sprintf("%.2g",probability) as prob from event_probs;
$ select sprintf('<td color="%s">%s</td>',color,content) as td_cell from cells;

I considered a plperl function to do this, but plperl can't take anyarray and that means that I'd have to resort to ugliness like coding for specific numbers of args or encoding args them within in a single string... ick!

Is there a way to get more flexible formatting as in these examples within a backend query, even if not with sprintf per se?

Thanks,
Reece

-- 
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0

В списке pgsql-general по дате отправления:

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: problem with postgres SQL db
Следующее
От: John Gunther
Дата:
Сообщение: Locale, encoding, sort order confusion