Re: One-shot expanded output in psql using \gx

David Fetter <david@fetter.org>

From: David Fetter <david@fetter.org>
To: Christoph Berg <christoph.berg@credativ.de>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2017-02-08T15:12:14Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. psql: Fix \gx when FETCH_COUNT is used

  2. psql: Add \gx command

On Wed, Feb 08, 2017 at 03:52:40PM +0100, Christoph Berg wrote:
> Re: David Fetter 2017-02-07 <20170207051659.GC3552@fetter.org>
> > On Mon, Feb 06, 2017 at 08:54:13PM +0100, Christoph Berg wrote:
> > > The majority of voices here was in favor of using \gx, so here is
> > > another version of the same patch which implements that.
> > 
> > Patch is useful, and works as documented.
> > 
> > Maybe it could get a test or two in src/test/regress/*/psql.*
> 
> Good point. The new version tests \g and \gx with a new query, and
> re-running it on the last query buffer.
>   
> ! 	/* \g [filename] -- send query, optionally with output to file/pipe */
> ! 	else if (strcmp(cmd, "g") == 0)
>   	{
>   		char	   *fname = psql_scan_slash_option(scan_state,
>   												   OT_FILEPIPE, NULL, false);
> --- 910,920 ----
>   		free(fname);
>   	}
>   
> ! 	/*
> ! 	 * \g [filename] -- send query, optionally with output to file/pipe
> ! 	 * \gx [filename] -- same as \g, with expanded mode forced
> ! 	 */
> ! 	else if (strcmp(cmd, "g") == 0 || strcmp(cmd, "gx") == 0)
>   	{
>   		char	   *fname = psql_scan_slash_option(scan_state,
>   												   OT_FILEPIPE, NULL, false);
> *************** exec_command(const char *cmd,
> *** 924,929 ****
> --- 927,934 ----
>   			pset.gfname = pg_strdup(fname);
>   		}
>   		free(fname);
> + 		if (strcmp(cmd, "gx") == 0)
> + 			pset.g_expanded = true;
>   		status = PSQL_CMD_SEND;
>   	}

Would you be open to saving the next person some work by doing
something similar to how \d is done, namely looking for an 'x'
modifier after g without regard to how far after?  As of this writing,
the \d version starts at line 398 in master.

Best,
David.
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate