Re: string function - "format" function proposal

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: string function - "format" function proposal
Date: 2010-09-01 04:29:28
Message-ID: AANLkTimcxpadu_U5_RvSDHoP_H6o26XEuJ27D7+ZPbX4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2010/9/1 Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>:
> On Wed, Sep 1, 2010 at 6:07 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> I don't found a nice mix for placeholders and positional placeholders
>
> How about %pos$format, used in C-printf()? It might be
> only in Linux's libc.
>
> printf("<%2$s> <%1$d>\n", 123, "abc");
> => <abc> <123>
> http://linux.die.net/man/3/printf

same syntax I designed and didn't implement, because it isn't too
readable (my opinion). But I am not against - just thinking so
separate function can be better.
>
>> %i ... sql identifier
>> %v ... sql value
>> %s ... string --- the most used tag I expect
>> %l ... literal
>
> Looks good designed.  I have a couple of comments and questions:
>
> * There is no examples for %l. What's the difference from %v and %s?
>  If it always quotes, how does it work? Like as quote_literal()
>  or quote_nullable()?
>

%l is always quoted

it is designed for syntax: SELECT integer '10';

%s versus %v ... %s is never quoted X %v is quoted when it is
necessary, NULL is showed as empty string for %s and as "NULL" for %v.
%s is used for messages (the behave is same like "concat"), %v is used
for SQL statement building

> * %v quotes text values (and maybe all non-numeric values) with
>  single quotes, but doesn't numeric values. How do we determine
>  the difference? By type oid?
>

every datatype has typecategory attribute

typname │ typcategory
─────────────────┼─────────────
int8 │ N
int2 │ N
int4 │ N
regproc │ N
oid │ N
float4 │ N
float8 │ N
money │ N
numeric │ N
regprocedure │ N
regoper │ N
regoperator │ N
regclass │ N
regtype │ N
regconfig │ N
regdictionary │ N
cardinal_number │ N

so these types are unquoted

> * %v also doesn't quote boolean values, but t and f are not valid.
>  You should use true and false (or 't' and 'f') for the cases.
>  (So, your "INSERT INTO" example is broken.)
>

you have a true - it should be fixed

Regards

Pavel

> --
> Itagaki Takahiro
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2010-09-01 05:33:07 Re: Synchronous replication - patch status inquiry
Previous Message Pavel Stehule 2010-09-01 04:14:50 Re: string function - "format" function proposal