Re: more psprintf() use

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: more psprintf() use
Date: 2014-01-02 19:12:45
Message-ID: 20140102191245.GA7035@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2014-01-02 19:16:01 Re: proposal: multiple read-write masters in a cluster with wal-streaming synchronization
Previous Message Tom Lane 2014-01-02 19:10:17 Re: [PATCH] Negative Transition Aggregate Functions (WIP)