Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Daniel Verite <daniel(at)manitou-mail(dot)org>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Erik Rijkers <er(at)xs4all(dot)nl>, Robert Haas <robertmhaas(at)gmail(dot)com>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org>, pgsql-hackers-owner(at)postgresql(dot)org
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: 2017-03-27 13:53:35
Message-ID: alpine.DEB.2.20.1703270655240.20202@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> ISTM that PQExpBuffer is partially a memory leak. Something should need
>> to be freed?
> I copied that pattern from somewhere else, so yeah, I duplicated whatever
> leak was there.

Hmmm. Indeed some commands do not free, but there is a single use and the
commands exits afterwards, eg "createuser".

I think that you could use another pattern where you init the
PQExpBufferData structure instead of create it, so that only the string is

>> I think that you should use appendPQExpBufferChar and Str instead of
>> relying on the format variant which is probably expensive. Something like:
>> if (num_options > 0)
>> append...Char(buf, ' ');
>> append...Str(buf, ...);
> All flavors of appendPQExpBuffer*() I can find have a const *char format
> string, so no way to append a naked string. If you know differently, I'm
> listening. Not fixed.

These prototypes are from "pqexpbuffer.h", and do not seem to rely on a

extern void appendPQExpBufferChar(PQExpBuffer str, char ch);
extern void appendPQExpBufferStr(PQExpBuffer str, const char *data);


In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-03-27 13:54:13 Re: crashes due to setting max_parallel_workers=0
Previous Message Andreas Karlsson 2017-03-27 13:50:29 Re: Refactor handling of database attributes between pg_dump and pg_dumpall