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

From Pavel Stehule
Subject proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used
Date
Msg-id CAFj8pRB95BMye6eaRZzpNf3N8HLnZjE+N43DFadHRJ6u+536qA@mail.gmail.com
Whole thread Raw
Responses Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used  (Stephen Frost <sfrost@snowman.net>)
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Do we need so many hint bits?
Next
From: Amit Kapila
Date:
Subject: Re: Proposal for Allow postgresql.conf values to be changed via SQL