Re: format() with embedded to_char() formatter

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: format() with embedded to_char() formatter
Date: 2010-11-22 12:54:53
Message-ID: AANLkTikFCqyP0-c-49s7dBsSFrqeAumdnCR4Pqa-L_at@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

There is little bit complication. There are no one "to_char" function
- so you cannot to use DirectFunctionCall API.

but I am not against to this proposal.

regards

Pavel

2010/11/22 Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>:
> 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
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2010-11-22 12:55:54 Re: patch: fix performance problems with repated decomprimation of varlena values in plpgsql
Previous Message Pavel Stehule 2010-11-22 12:46:51 patch: fix performance problems with repated decomprimation of varlena values in plpgsql