Re: format() with embedded to_char() formatter

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: format() with embedded to_char() formatter
Date: 2010-11-22 17:04:31
Message-ID: AANLkTikF_BfsfA6gRqFtwmQ28xkas6kH=LBPCuGPu=zQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 22, 2010 at 9:55 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com> writes:
>> 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.
>
> This seems pretty gross, not least because the existing to_char
> functions are so limited and broken.  I don't really want to make
> format() incorporate all the brain damage in timestamp to_char, in
> particular.

If the existing to_char() functions are limited and broken, maybe we
ought to fix them. I am reminded of some wit's quote that XML is like
violence - if it doesn't solve your problem, you aren't using enough
of it. I'm not a believer in that philosophy, and don't think that
adding a whole new set of functions with incompatible semantics is the
right way to fix problems with the existing functions. We have enough
of that already - especially around dates - and it sucks badly enough
as it is. Non-orthogonality is bad.

> Also, it doesn't seem that you're really getting much
> notational leverage with this proposal.

I am not sure I agree. It seems quite convenient to me to be able to
encode all the formatting crap in the message string, rather than
spreading it out all over the SQL statement. Maybe time for another
poll on -general.

> And lastly, AFAICS there
> is no way to do what you suggest without some really ugly kluges
> in the parser --- I think the function parsing code would have to
> have special cases to make format() work like this.

Huh?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2010-11-22 17:05:58 Re: Re: Proposed Windows-specific change: Enable crash dumps (like core files)
Previous Message Andrew Dunstan 2010-11-22 17:02:54 Re: dblink versus long connection strings