Re: string function - "format" function proposal

From: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: string function - "format" function proposal
Date: 2010-08-30 11:20:54
Message-ID: AANLkTi=J4MMFbczzBU11zhxDY7KNf_hkXHEr16s6JkZP@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 30, 2010 at 7:58 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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')

* 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.

--
Itagaki Takahiro

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2010-08-30 11:51:55 Re: string function - "format" function proposal
Previous Message Pavel Stehule 2010-08-30 10:58:31 string function - "format" function proposal