psql_gx_fetch_count_v1.patch
application/octet-stream
Filename: psql_gx_fetch_count_v1.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/bin/psql/common.c | 4 | 0 |
| src/test/regress/expected/psql.out | 25 | 0 |
| src/test/regress/sql/psql.sql | 10 | 0 |
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 044cdb82a7..a41932ff27 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1565,6 +1565,10 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
"FETCH FORWARD %d FROM _psql_cursor",
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 */
if (pset.gfname)
{
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index d602aeef42..4aaf4c1620 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -51,6 +51,31 @@ four | 4
3 | 4
(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
select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_
\echo :pref01_test01 :pref01_test02 :pref01_test03
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index b56a05f7f0..4a676c3119 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -28,6 +28,16 @@ SELECT 1 as one, 2 as two \g
SELECT 3 as three, 4 as four \gx
\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
select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_