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

Pavel Stehule <pavel.stehule@gmail.com>

From: Pavel Stehule <pavel.stehule@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2012-11-16T09:42:26Z
Lists: pgsql-hackers

Attachments

Hello

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.

postgres=# select format('||%4s|| ||%-4s||', 'ab', 'ab');
      format
-------------------
 ||  ab|| ||ab  ||

I also found so our implementation of positional and ordered
placeholders are not correct.

-- correct
postgres=# select format('%s %2$s %s', 'Hello', 'World');
      format
-------------------
 Hello World World

-- our current behave
postgres=# select format('%s %2$s %s', 'Hello', 'World');
ERROR:  too few arguments for format
postgres=#

Comments, notices?

Regards

Pavel Stehule