Re: string function - "format" function proposal

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: string function - "format" function proposal
Дата
Msg-id 1283181390-sup-7985@alvh.no-ip.org
обсуждение исходный текст
Ответ на Re: string function - "format" function proposal  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: string function - "format" function proposal  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-hackers
Excerpts from Pavel Stehule's message of lun ago 30 07:51:55 -0400 2010:
> 2010/8/30 Itagaki Takahiro <itagaki.takahiro@gmail.com>:
> > On Mon, Aug 30, 2010 at 7:58 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> >> propsals:
> >> * "format" function - uses same formatting as PL/pgSQL RAISE statement
> >> * "sprintf" function
> >>
> >> Now I propose a compromise - "format" function with only three tags:
> >> %s .. some string
> >> %i  .. SQL identifier
> >> %l  .. string literal
> >
> > These are just ideas:
> >
> > * Use $n, as like as PREPARE command.
> >  It allows for us to swap arguments in any order.
> >  SELECT format('$2 before $1', 'aaa', 'bbb')
> 
> what is use case for this feature? I don't see it.

Translations :-)  I haven't had a use for that but I've heard people
implements gettext of sorts in database tables.  Maybe that kind of
thing would be of use here.

> > * Call to_char() functions for each placeholder.
> >  For example,
> >    format('=={YYYY-MM-DD}==', tm::timestamp)
> >  is equivalent to
> >    '==' || to_char(tm, 'YYYY-MM-DD') || '=='
> >  '{}' prints the input with the default format.
> >
> > New languages' libraries might be of some help. LLs, C#, etc.
> 
> I though about integration with to_char function too. There are not
> technical barrier. And I can live with just {to_char_format} too. It
> can be or cannot be mixed with basic tags together - there is
> specified a NULL value behave. If we allow {format} syntax, then we
> have to specify a escape syntax for { and }. Do you have a some idea?

What about %{sth}?  That way you don't need to escape {.  The closing } would
need escaping only inside the %{} specifier, so {%{YYYY{\}MM}} prints
{2010{}08}  So the above example is:

format('==%{YYYY-MM-DD}==', tm::timestamp);

Not sure about this to_char stuff though, seems too cute.  You can do
the case above like this:

format('==%s==', to_char(tm::timestamp, 'YYYY-MM-DD'))

-- 
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


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

Предыдущее
От: "Kevin Grittner"
Дата:
Сообщение: Re: Assertion failure on HEAD (or at least git copy of it)
Следующее
От: Joe Conway
Дата:
Сообщение: Re: Assertion failure on HEAD (or at least git copy of it)