{"Entry":{"collection":"psql","key":"cmd-67-65-78-65-63","name":"\\gexec","aliases":["\\gexec"],"metadata":{"aliases":["\\gexec"],"category":"Query execution","content_hash":"56e7558c9ada67437a877793dbc3ba124138092da82cfc13a418d58df37715a8","imported_at":"2026-09-30T00:40:45.036584+08:00","name":"\\gexec","name_zh":"","slug":"cmd-67-65-78-65-63","summary":"Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of my_table :"}},"Definition":{"Collection":"psql","Key":"cmd-67-65-78-65-63","SourceDatabase":"center","Version":"18","SourceTable":"psql_command","SourceKey":"cmd-67-65-78-65-63","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"command":"\\gexec","comparison_data":{"definition":"Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of my_table : =\u003e SELECT format('create index on my_table(%I)', attname) -\u003e FROM pg_attribute -\u003e WHERE attrelid = 'my_table'::regclass AND attnum \u003e 0 -\u003e ORDER BY attnum -\u003e \\gexec CREATE INDEX CREATE INDEX CREATE INDEX CREATE INDEX The generated queries are executed in the order in which the rows are returned, and left-to-right within each row if there is more than one column. NULL fields are ignored. The generated queries are sent literally to the server for processing, so they cannot be psql meta-commands nor contain psql variable references. If any individual query fails, execution of the remaining queries continues unless ON_ERROR_STOP is set. Execution of each query is subject to ECHO processing. (Setting ECHO to all or queries is often advisable when using \\gexec .) Query logging, single-step mode, timing, and other query execution features apply to each generated query as well. If the current query buffer is empty, the most recently sent query is re-executed instead.","modifiers":[],"signature":"\\gexec","spellings":["\\gexec"]},"comparison_hash":"4df526f59b23b5fa24e30caba1236c2988d5db04c457b5b38354014b2b052ac6","description":["Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of my_table :"],"facts":[{"label":"Client","value":"psql 18.6"},{"label":"Case-sensitive spelling","value":"\\gexec"}],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"APP-PSQL-META-COMMAND-GEXEC\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\gexec\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eSends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of \u003ccode class=\"structname\"\u003emy_table\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003e=\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eSELECT format('create index on my_table(%I)', attname)\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eFROM pg_attribute\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eWHERE attrelid = 'my_table'::regclass AND attnum \u0026gt; 0\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eORDER BY attnum\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003e\\gexec\u003c/code\u003e\u003c/strong\u003e\nCREATE INDEX\nCREATE INDEX\nCREATE INDEX\nCREATE INDEX\n\u003c/pre\u003e\n\u003cp\u003eThe generated queries are executed in the order in which the rows are returned, and left-to-right within each row if there is more than one column. NULL fields are ignored. The generated queries are sent literally to the server for processing, so they cannot be \u003cspan class=\"application\"\u003epsql\u003c/span\u003e meta-commands nor contain \u003cspan class=\"application\"\u003epsql\u003c/span\u003e variable references. If any individual query fails, execution of the remaining queries continues unless \u003ccode class=\"varname\"\u003eON_ERROR_STOP\u003c/code\u003e is set. Execution of each query is subject to \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e processing. (Setting \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e to \u003ccode class=\"literal\"\u003eall\u003c/code\u003e or \u003ccode class=\"literal\"\u003equeries\u003c/code\u003e is often advisable when using \u003ccode class=\"command\"\u003e\\gexec\u003c/code\u003e.) Query logging, single-step mode, timing, and other query execution features apply to each generated query as well.\u003c/p\u003e\n\u003cp\u003eIf the current query buffer is empty, the most recently sent query is re-executed instead.\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","manual_path":"app-psql.html#APP-PSQL-META-COMMAND-GEXEC","modifiers":[],"related":[{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"signature":"\\gexec","sources":[{"anchor":"APP-PSQL-META-COMMAND-GEXEC","file":"app-psql.html","label":"18.6 English manual · app-psql.html","sha256":"fa2a1d39294b8854318e82e93f71272c645ed88150ecc2786c28902c3f32782c","url":"/docs/18/app-psql.html#APP-PSQL-META-COMMAND-GEXEC"}],"spellings":["\\gexec"],"tables":[{"columns":[{"key":"command","label":"Command"},{"key":"modifiers","label":"Documented suffix modifiers"}],"key":"spellings","rows":[{"command":{"text":"\\gexec","url":"/wiki/psql/cmd-67-65-78-65-63/?v=18"},"modifiers":"None listed in this signature"}],"title":"Spellings in this manual definition"}]},"ManualEvidence":{"manual_path":"app-psql.html#APP-PSQL-META-COMMAND-GEXEC","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"anchor":"APP-PSQL-META-COMMAND-GEXEC","file":"app-psql.html","label":"18.6 English manual · app-psql.html","sha256":"fa2a1d39294b8854318e82e93f71272c645ed88150ecc2786c28902c3f32782c","url":"/docs/18/app-psql.html#APP-PSQL-META-COMMAND-GEXEC"}]},"MeasuredEvidence":{}},"Text":{"Collection":"psql","Key":"cmd-67-65-78-65-63","SourceDatabase":"center","Version":"18","Locale":"en","Title":"\\gexec","Summary":"Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of my_table :","BodyHTML":"\u003cdiv\u003e\u003cdl\u003e\u003cdt id=\"APP-PSQL-META-COMMAND-GEXEC\"\u003e\u003cspan\u003e\u003ccode\u003e\\gexec\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eSends the current query buffer to the server, then treats each column of each row of the query\u0026#39;s output (if any) as an SQL statement to be executed. For example, to create an index on each column of \u003ccode\u003emy_table\u003c/code\u003e:\u003c/p\u003e\n\u003cpre\u003e=\u0026gt; \u003cstrong\u003e\u003ccode\u003eSELECT format(\u0026#39;create index on my_table(%I)\u0026#39;, attname)\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong\u003e\u003ccode\u003eFROM pg_attribute\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong\u003e\u003ccode\u003eWHERE attrelid = \u0026#39;my_table\u0026#39;::regclass AND attnum \u0026gt; 0\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong\u003e\u003ccode\u003eORDER BY attnum\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong\u003e\u003ccode\u003e\\gexec\u003c/code\u003e\u003c/strong\u003e\nCREATE INDEX\nCREATE INDEX\nCREATE INDEX\nCREATE INDEX\n\u003c/pre\u003e\n\u003cp\u003eThe generated queries are executed in the order in which the rows are returned, and left-to-right within each row if there is more than one column. NULL fields are ignored. The generated queries are sent literally to the server for processing, so they cannot be \u003cspan\u003epsql\u003c/span\u003e meta-commands nor contain \u003cspan\u003epsql\u003c/span\u003e variable references. If any individual query fails, execution of the remaining queries continues unless \u003ccode\u003eON_ERROR_STOP\u003c/code\u003e is set. Execution of each query is subject to \u003ccode\u003eECHO\u003c/code\u003e processing. (Setting \u003ccode\u003eECHO\u003c/code\u003e to \u003ccode\u003eall\u003c/code\u003e or \u003ccode\u003equeries\u003c/code\u003e is often advisable when using \u003ccode\u003e\\gexec\u003c/code\u003e.) Query logging, single-step mode, timing, and other query execution features apply to each generated query as well.\u003c/p\u003e\n\u003cp\u003eIf the current query buffer is empty, the most recently sent query is re-executed instead.\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"58bca3b26d04a2fc45cd1b89e5e366769f03257db6e75fee2f34f49db5682997","Payload":{"description":["Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of my_table :"],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"APP-PSQL-META-COMMAND-GEXEC\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\gexec\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\n\u003cp\u003eSends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed. For example, to create an index on each column of \u003ccode class=\"structname\"\u003emy_table\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003e=\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eSELECT format('create index on my_table(%I)', attname)\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eFROM pg_attribute\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eWHERE attrelid = 'my_table'::regclass AND attnum \u0026gt; 0\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eORDER BY attnum\u003c/code\u003e\u003c/strong\u003e\n-\u0026gt; \u003cstrong class=\"userinput\"\u003e\u003ccode\u003e\\gexec\u003c/code\u003e\u003c/strong\u003e\nCREATE INDEX\nCREATE INDEX\nCREATE INDEX\nCREATE INDEX\n\u003c/pre\u003e\n\u003cp\u003eThe generated queries are executed in the order in which the rows are returned, and left-to-right within each row if there is more than one column. NULL fields are ignored. The generated queries are sent literally to the server for processing, so they cannot be \u003cspan class=\"application\"\u003epsql\u003c/span\u003e meta-commands nor contain \u003cspan class=\"application\"\u003epsql\u003c/span\u003e variable references. If any individual query fails, execution of the remaining queries continues unless \u003ccode class=\"varname\"\u003eON_ERROR_STOP\u003c/code\u003e is set. Execution of each query is subject to \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e processing. (Setting \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e to \u003ccode class=\"literal\"\u003eall\u003c/code\u003e or \u003ccode class=\"literal\"\u003equeries\u003c/code\u003e is often advisable when using \u003ccode class=\"command\"\u003e\\gexec\u003c/code\u003e.) Query logging, single-step mode, timing, and other query execution features apply to each generated query as well.\u003c/p\u003e\n\u003cp\u003eIf the current query buffer is empty, the most recently sent query is re-executed instead.\u003c/p\u003e\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","related":[{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"sections":[],"tables":[{"columns":[{"key":"command","label":"Command"},{"key":"modifiers","label":"Documented suffix modifiers"}],"key":"spellings","rows":[{"command":{"text":"\\gexec","url":"/wiki/psql/cmd-67-65-78-65-63/?v=18"},"modifiers":"None listed in this signature"}],"title":"Spellings in this manual definition"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":[{"Version":"18","Ordinal":0,"Command":"\\gexec","Signature":"\\gexec","Modifiers":[]}],"SQLState":null,"Evidence":null}
