mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	psql: Fix \gx when FETCH_COUNT is used
Set expanded output when requested through \gx in ExecQueryUsingCursor() (used when FETCH_COUNT is set). Discussion: https://www.postgresql.org/message-id/CB7A53AA-5645-4BDD-AB07-4D22CD9D8FF1%40gmx.net Author: Tobias Bussmann
This commit is contained in:
		| @@ -1565,6 +1565,10 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec) | |||||||
| 			 "FETCH FORWARD %d FROM _psql_cursor", | 			 "FETCH FORWARD %d FROM _psql_cursor", | ||||||
| 			 fetch_count); | 			 fetch_count); | ||||||
|  |  | ||||||
|  | 	/* one-shot expanded output requested via \gx */ | ||||||
|  | 	if (pset.g_expanded) | ||||||
|  | 		my_popt.topt.expanded = 1; | ||||||
|  |  | ||||||
| 	/* prepare to write output to \g argument, if any */ | 	/* prepare to write output to \g argument, if any */ | ||||||
| 	if (pset.gfname) | 	if (pset.gfname) | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -51,6 +51,31 @@ four  | 4 | |||||||
|      3 |    4 |      3 |    4 | ||||||
| (1 row) | (1 row) | ||||||
|  |  | ||||||
|  | -- \gx should work in FETCH_COUNT mode too | ||||||
|  | \set FETCH_COUNT 1 | ||||||
|  | SELECT 1 as one, 2 as two \g | ||||||
|  |  one | two  | ||||||
|  | -----+----- | ||||||
|  |    1 |   2 | ||||||
|  | (1 row) | ||||||
|  |  | ||||||
|  | \gx | ||||||
|  | -[ RECORD 1 ] | ||||||
|  | one | 1 | ||||||
|  | two | 2 | ||||||
|  |  | ||||||
|  | SELECT 3 as three, 4 as four \gx | ||||||
|  | -[ RECORD 1 ] | ||||||
|  | three | 3 | ||||||
|  | four  | 4 | ||||||
|  |  | ||||||
|  | \g | ||||||
|  |  three | four  | ||||||
|  | -------+------ | ||||||
|  |      3 |    4 | ||||||
|  | (1 row) | ||||||
|  |  | ||||||
|  | \unset FETCH_COUNT | ||||||
| -- \gset | -- \gset | ||||||
| select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_ | select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_ | ||||||
| \echo :pref01_test01 :pref01_test02 :pref01_test03 | \echo :pref01_test01 :pref01_test02 :pref01_test03 | ||||||
|   | |||||||
| @@ -28,6 +28,16 @@ SELECT 1 as one, 2 as two \g | |||||||
| SELECT 3 as three, 4 as four \gx | SELECT 3 as three, 4 as four \gx | ||||||
| \g | \g | ||||||
|  |  | ||||||
|  | -- \gx should work in FETCH_COUNT mode too | ||||||
|  | \set FETCH_COUNT 1 | ||||||
|  |  | ||||||
|  | SELECT 1 as one, 2 as two \g | ||||||
|  | \gx | ||||||
|  | SELECT 3 as three, 4 as four \gx | ||||||
|  | \g | ||||||
|  |  | ||||||
|  | \unset FETCH_COUNT | ||||||
|  |  | ||||||
| -- \gset | -- \gset | ||||||
|  |  | ||||||
| select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_ | select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user