initdb: Refactor PG_CMD_PUTS loops

Started by Peter Eisentrautover 3 years ago4 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

Keeping the SQL commands that initdb runs in string arrays before
feeding them to PG_CMD_PUTS() seems unnecessarily verbose and
inflexible. In some cases, the array only has one member. In other
cases, one might want to use PG_CMD_PRINTF() instead, to parametrize a
command, but that would require breaking up the loop or using
workarounds like replace_token(). This patch unwinds all that; it's
much simpler that way.

Attachments:

0001-initdb-Refactor-PG_CMD_PUTS-loops.patchtext/plain; charset=UTF-8; name=0001-initdb-Refactor-PG_CMD_PUTS-loops.patchDownload+170-210
#2John Naylor
john.naylor@enterprisedb.com
In reply to: Peter Eisentraut (#1)
Re: initdb: Refactor PG_CMD_PUTS loops

On Thu, Dec 1, 2022 at 5:02 PM Peter Eisentraut <
peter.eisentraut@enterprisedb.com> wrote:

Keeping the SQL commands that initdb runs in string arrays before
feeding them to PG_CMD_PUTS() seems unnecessarily verbose and
inflexible. In some cases, the array only has one member. In other
cases, one might want to use PG_CMD_PRINTF() instead, to parametrize a
command, but that would require breaking up the loop or using
workarounds like replace_token(). This patch unwinds all that; it's
much simpler that way.

+1, I can't think of a reason to keep the current coding

--
John Naylor
EDB: http://www.enterprisedb.com

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Peter Eisentraut (#1)
Re: initdb: Refactor PG_CMD_PUTS loops

On 2022-12-01 Th 05:02, Peter Eisentraut wrote:

Keeping the SQL commands that initdb runs in string arrays before
feeding them to PG_CMD_PUTS() seems unnecessarily verbose and
inflexible.  In some cases, the array only has one member.  In other
cases, one might want to use PG_CMD_PRINTF() instead, to parametrize a
command, but that would require breaking up the loop or using
workarounds like replace_token().  This patch unwinds all that; it's
much simpler that way.

Looks reasonable. (Most of this dates back to 2003/2004, the very early
days of initdb.c.)

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Andrew Dunstan (#3)
Re: initdb: Refactor PG_CMD_PUTS loops

On 02.12.22 15:07, Andrew Dunstan wrote:

On 2022-12-01 Th 05:02, Peter Eisentraut wrote:

Keeping the SQL commands that initdb runs in string arrays before
feeding them to PG_CMD_PUTS() seems unnecessarily verbose and
inflexible.  In some cases, the array only has one member.  In other
cases, one might want to use PG_CMD_PRINTF() instead, to parametrize a
command, but that would require breaking up the loop or using
workarounds like replace_token().  This patch unwinds all that; it's
much simpler that way.

Looks reasonable. (Most of this dates back to 2003/2004, the very early
days of initdb.c.)

committed