Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used
Date: 2012-12-29 18:53:51
Message-ID: CAFj8pRB-+nAdDSLk71GHctf1XY4buqj-y43uC0nmc6+F4thvPQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

2012/12/29 Stephen Frost <sfrost(at)snowman(dot)net>:
> Pavel,
>
> * Pavel Stehule (pavel(dot)stehule(at)gmail(dot)com) wrote:
>> I found so we doesn't have functionality for simply text aligning - so
>> I propose support width for %s like printf's behave. glibc
>> implementation knows a rule for precision, that I don't would to
>> implement, because it is oriented to bytes and not to chars - and it
>> can be confusing. Still I would to have implementation and design of
>> "format" function maximally simple - and a rule for "s" specifier and
>> width is clean and simple.
>
> I started looking at this patch to get a head-start on the next
> commitfest. There's no documentation, which certainly needs to be
> fixed, but worse, this doesn't appear to match glibc printf and it's not
> entirely clear to me why it doesn't.
>
>> -- our current behave
>> postgres=# select format('%s %2$s %s', 'Hello', 'World');
>> ERROR: too few arguments for format
>> postgres=#
>
> This is correct, if we're matching glibc (and SUS, I believe), isn't it?
> You're not allowed to mix '%2$s' type parameters and '%s' in a single
> format.

I am not sure, please recheck

pavel ~ $ cat test.c
#include <stdio.h>

void main()
{

printf("%s %2$s %s\n", "AHOJ", "Svete");
}

pavel ~ $ gcc test.c # no warning here
pavel ~ $ gcc --version
gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

pavel ~ $ ./a.out
AHOJ Svete Svete
pavel ~ $

Regards

Pavel Stehule

>
> Thanks,
>
> Stephen

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2012-12-29 18:56:09 Re: My first patch! (to \df output)
Previous Message Stephen Frost 2012-12-29 18:44:59 Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used