Re: more psprintf() use - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: more psprintf() use
Date
Msg-id 52C9C0E3.7000307@gmx.net
Whole thread Raw
In response to Re: more psprintf() use  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-hackers
On 1/2/14, 2:12 PM, Alvaro Herrera wrote:
> Peter Eisentraut wrote:
> 
>> psprintf() in place of hardcoded palloc(N) + sprintf() and the like.
>>
> 
>> +    values[j++] = psprintf("%d", stat.blkno);
>> +    values[j++] = psprintf("%c", stat.type);
>> +    values[j++] = psprintf("%d", stat.live_items);
>> +    values[j++] = psprintf("%d", stat.dead_items);
>> +    values[j++] = psprintf("%d", stat.avg_item_size);
>> +    values[j++] = psprintf("%d", stat.page_size);
>> +    values[j++] = psprintf("%d", stat.free_size);
>> +    values[j++] = psprintf("%d", stat.btpo_prev);
>> +    values[j++] = psprintf("%d", stat.btpo_next);
>> +    values[j++] = psprintf("%d", (stat.type == 'd') ? stat.btpo.xact : stat.btpo.level);
>> +    values[j++] = psprintf("%d", stat.btpo_flags);
>>  
>>      tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc),
>>                                     values);
> 
> In cases such as this one, I have often wondered whether it'd be better
> to write this as DatumGetSometype() plus heap_form_tuple, instead of
> printing to strings and then building a tuple from those.

Probably.  As you can see, this style is only used in a few contrib
modules that all came from the same source, I think.




pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: more psprintf() use
Next
From: Emre Hasegeli
Date:
Subject: Re: GiST support for inet datatypes