{"Entry":{"collection":"psql","key":"cmd-67-65-78-65-63","name":"\\gexec","aliases":["\\gexec"],"metadata":{"aliases":["\\gexec"],"category":"Query execution","content_hash":"56e7558c9ada67437a877793dbc3ba124138092da82cfc13a418d58df37715a8","derived_content_hash":"62279d26a7cb7c0407ac6955dd1be1fe5db160ee13ef970aad4910f6c4abde29","documentation_refresh":{"batch":"20261113","original_source_rev":"","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"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":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","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 :"],"description_zh":"将当前查询缓冲区发送到服务器，然后将查询输出的每行每列视为要执行的 SQL 语句。例如，要在 my_table 的每一列上创建索引：","description_zh_html":"\u003cdd\u003e\u003cp\u003e\n         将当前查询缓冲区发送到服务器，然后将查询输出的每行每列视为要执行的 SQL 语句。例如，要在 \u003ccode class=\"structname\"\u003emy_table\u003c/code\u003e 的每一列上创建索引：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\n=\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\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n         生成的查询按照返回行的顺序执行；如果有多列，则在每行内从左到右执行。NULL 字段会被忽略。生成的查询按原样发送到服务器进行处理，因此不能是 \u003cspan class=\"application\"\u003epsql\u003c/span\u003e 元命令，也不能包含 \u003cspan class=\"application\"\u003epsql\u003c/span\u003e 变量引用。如果某个查询失败，仍会继续执行其余查询，除非设置了 \u003ccode class=\"varname\"\u003eON_ERROR_STOP\u003c/code\u003e。每个查询的执行都受 \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e 处理的影响。（通常，在使用\u003ccode class=\"command\"\u003e\\gexec\u003c/code\u003e 时，适宜将 \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e 设为 \u003ccode class=\"literal\"\u003eall\u003c/code\u003e 或 \u003ccode class=\"literal\"\u003equeries\u003c/code\u003e。）查询日志、单步模式、计时及其他查询执行功能也适用于每个生成的查询。\n        \u003c/p\u003e\u003cp\u003e\n         如果当前查询缓冲区为空，则重新执行最近发送的查询。\n        \u003c/p\u003e\u003c/dd\u003e","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"},"facts":[{"label":"Client","value":"psql 18.7"},{"label":"Case-sensitive spelling","value":"\\gexec"}],"facts_zh":[{"label":"客户端","value":"psql 18.7"},{"label":"区分大小写的写法","value":"\\gexec"}],"localization":{"documentation_release":"18.7","language":"en","source_language":"en","source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552","status":"same-version-reviewed-manual"},"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\u003cp\u003e\n         Sends the current query buffer to the server, then treats\n         each column of each row of the query's output (if any) as an SQL\n         statement to be executed.  For example, to create an index on each\n         column of \u003ccode class=\"structname\"\u003emy_table\u003c/code\u003e:\n\u003c/p\u003e\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\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n         The generated queries are executed in the order in which the rows\n         are returned, and left-to-right within each row if there is more\n         than one column.  NULL fields are ignored.  The generated queries\n         are sent literally to the server for processing, so they cannot be\n         \u003cspan class=\"application\"\u003epsql\u003c/span\u003e meta-commands nor contain \u003cspan class=\"application\"\u003epsql\u003c/span\u003e\n         variable references.  If any individual query fails, execution of\n         the remaining queries continues\n         unless \u003ccode class=\"varname\"\u003eON_ERROR_STOP\u003c/code\u003e is set.  Execution of each\n         query is subject to \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e processing.\n         (Setting \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e to \u003ccode class=\"literal\"\u003eall\u003c/code\u003e\n         or \u003ccode class=\"literal\"\u003equeries\u003c/code\u003e is often advisable when\n         using \u003ccode class=\"command\"\u003e\\gexec\u003c/code\u003e.)  Query logging, single-step mode,\n         timing, and other query execution features apply to each generated\n         query as well.\n        \u003c/p\u003e\u003cp\u003e\n         If the current query buffer is empty, the most recently sent query\n         is re-executed instead.\n        \u003c/p\u003e\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"}],"related_zh":[{"label":"psql 命令行选项及完整手册","url":"/wiki/tool/psql/?v=18"}],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.7","major":"18","manifest":{"major":"18","release":"18.7","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd","source_url":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2"},"ref":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2","revision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd"},"sections":[],"sections_zh":[],"signature":"\\gexec","sources":[{"anchor":"APP-PSQL-META-COMMAND-GEXEC","file":"app-psql.html","label":"18.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","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"}],"tables_zh":[{"columns":[{"key":"command","label":"命令"},{"key":"modifiers","label":"手册中的后缀修饰符"}],"key":"spellings","rows":[{"command":{"text":"\\gexec","url":"/wiki/psql/cmd-67-65-78-65-63/?v=18"},"modifiers":"此语法签名未列出"}],"title":"本版手册中的写法"}],"zh_from":"same-version-manual"},"ManualEvidence":{"manual_path":"app-psql.html#APP-PSQL-META-COMMAND-GEXEC","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.7","major":"18","manifest":{"major":"18","release":"18.7","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd","source_url":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2"},"ref":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2","revision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd"},"sources":[{"anchor":"APP-PSQL-META-COMMAND-GEXEC","file":"app-psql.html","label":"18.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","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\u003cp\u003e\n         Sends the current query buffer to the server, then treats\n         each column of each row of the query\u0026#39;s output (if any) as an SQL\n         statement to be executed.  For example, to create an index on each\n         column of \u003ccode\u003emy_table\u003c/code\u003e:\n\u003c/p\u003e\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\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n         The generated queries are executed in the order in which the rows\n         are returned, and left-to-right within each row if there is more\n         than one column.  NULL fields are ignored.  The generated queries\n         are sent literally to the server for processing, so they cannot be\n         \u003cspan\u003epsql\u003c/span\u003e meta-commands nor contain \u003cspan\u003epsql\u003c/span\u003e\n         variable references.  If any individual query fails, execution of\n         the remaining queries continues\n         unless \u003ccode\u003eON_ERROR_STOP\u003c/code\u003e is set.  Execution of each\n         query is subject to \u003ccode\u003eECHO\u003c/code\u003e processing.\n         (Setting \u003ccode\u003eECHO\u003c/code\u003e to \u003ccode\u003eall\u003c/code\u003e\n         or \u003ccode\u003equeries\u003c/code\u003e is often advisable when\n         using \u003ccode\u003e\\gexec\u003c/code\u003e.)  Query logging, single-step mode,\n         timing, and other query execution features apply to each generated\n         query as well.\n        \u003c/p\u003e\u003cp\u003e\n         If the current query buffer is empty, the most recently sent query\n         is re-executed instead.\n        \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","SourceRevision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","ContentHash":"f4e352b70452335337305ff769b90fa2dd277fc88a034be6d794f4ebf6f299a4","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\u003cp\u003e\n         Sends the current query buffer to the server, then treats\n         each column of each row of the query's output (if any) as an SQL\n         statement to be executed.  For example, to create an index on each\n         column of \u003ccode class=\"structname\"\u003emy_table\u003c/code\u003e:\n\u003c/p\u003e\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\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n         The generated queries are executed in the order in which the rows\n         are returned, and left-to-right within each row if there is more\n         than one column.  NULL fields are ignored.  The generated queries\n         are sent literally to the server for processing, so they cannot be\n         \u003cspan class=\"application\"\u003epsql\u003c/span\u003e meta-commands nor contain \u003cspan class=\"application\"\u003epsql\u003c/span\u003e\n         variable references.  If any individual query fails, execution of\n         the remaining queries continues\n         unless \u003ccode class=\"varname\"\u003eON_ERROR_STOP\u003c/code\u003e is set.  Execution of each\n         query is subject to \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e processing.\n         (Setting \u003ccode class=\"varname\"\u003eECHO\u003c/code\u003e to \u003ccode class=\"literal\"\u003eall\u003c/code\u003e\n         or \u003ccode class=\"literal\"\u003equeries\u003c/code\u003e is often advisable when\n         using \u003ccode class=\"command\"\u003e\\gexec\u003c/code\u003e.)  Query logging, single-step mode,\n         timing, and other query execution features apply to each generated\n         query as well.\n        \u003c/p\u003e\u003cp\u003e\n         If the current query buffer is empty, the most recently sent query\n         is re-executed instead.\n        \u003c/p\u003e\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":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":[{"Version":"18","Ordinal":0,"Command":"\\gexec","Signature":"\\gexec","Modifiers":[]}],"SQLState":null,"Evidence":null}
