format() with embedded to_char() formatter - Mailing list pgsql-hackers

From Itagaki Takahiro
Subject format() with embedded to_char() formatter
Date
Msg-id AANLkTikiGxJSmwWX7GQb4EcaO_qZzEaRWX4fXEjJSTf3@mail.gmail.com
Whole thread Raw
Responses Re: format() with embedded to_char() formatter
Re: format() with embedded to_char() formatter
List pgsql-hackers
format() function is very useful to construct formatted text,
but it doesn't support embedded formatter unlike sprintf() in C.
Of course, we can use to_char() functions for each argument value,
but embedded formatter would be more readable.

I'd like to propose %{...}s syntax, where format('%{xxx}s', arg)
is equivalent to format('%s', to_char(arg, 'xxx')). I think the
approach is better than implement C-like formatter because we
can reuse existing to_char() functions for the purpose.

Here are examples for the usage:

=# SELECT format('%{FM0000}s : %{YYYY-MM-DD}L', 123, current_timestamp);      format
---------------------0123 : '2010-11-22'

=# SELECT format('CREATE TABLE partition_%{YYYYMMDD}s () INHERITS
parent',  current_date);                      format
----------------------------------------------------CREATE TABLE partition_20101122 () INHERITS parent

Is it interesting? Comments welcome.

-- 
Itagaki Takahiro


pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Latches with weak memory ordering (Re: max_wal_senders must die)
Next
From: Magnus Hagander
Date:
Subject: Re: Explain analyze getrusage tracking