\gset
Sends the current query buffer to the server and stores the query's output into psql variables (see Variables below). The query to be executed must return exactly one row. Each column of the row is stored into a separate variable, named the same as the column. For example:
Reading PG 18·Select a recorded version
- Client
- psql 18.7
- Case-sensitive spelling
- \gset
- command
- \gset
- manual path
- app-psql.html#APP-PSQL-META-COMMAND-GSET
- modifiers
- Unknown
- signature
- \gset [ prefix ]
- spellings
- \gset
Definition PG 18
\gset [prefix]Sends the current query buffer to the server and stores the query's output into psql variables (see Variables below). The query to be executed must return exactly one row. Each column of the row is stored into a separate variable, named the same as the column. For example:
=>
SELECT 'hello' AS var1, 10 AS var2->\gset=>\echo :var1 :var2hello 10If you specify a
prefix, that string is prepended to the query's column names to create the variable names to use:=>
SELECT 'hello' AS var1, 10 AS var2->\gset result_=>\echo :result_var1 :result_var2hello 10If a column result is NULL, the corresponding variable is unset rather than being set.
If the query fails or does not return one row, no variables are changed.
If the current query buffer is empty, the most recently sent query is re-executed instead.
Exact case-sensitive spellings
\gset
Spellings in this manual definition
| Command | Documented suffix modifiers |
|---|---|
| \gset | None listed in this signature |
Compare versions
Complete source facts
documentation revision
{"inputs":[{"file":"app-psql.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","version":"18.7"},{"file":"app-psql.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"cb475c53a16d9e06358f5e6c9c5649645db92568cfd319f230c62c9f57ae090b","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"}Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · 1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915
Text language: en · 1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915