{"Entry":{"collection":"psql","key":"cmd-65-6c-73-65","name":"\\else","aliases":["\\else"],"metadata":{"aliases":["\\else"],"category":"Scripting and assistance","content_hash":"441a9524bb36a6f28e1f290b346e333a2150de140d1f17420f54e8b49eafb6f1","derived_content_hash":"5108bce53838dad44af87a161412809c43d33d02b2e7d923d90ee62de7833fb0","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:44.987521+08:00","name":"\\else","name_zh":"","slug":"cmd-65-6c-73-65","summary":"This group of commands implements nestable conditional blocks. A conditional block must begin with an \\if and end with an \\endif . In between there may be any number of \\elif clauses, which may optionally be followed by a single \\else clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block."}},"Definition":{"Collection":"psql","Key":"cmd-65-6c-73-65","SourceDatabase":"center","Version":"18","SourceTable":"psql_command","SourceKey":"cmd-65-6c-73-65","SourceRevision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","Facts":{"command":"\\else","comparison_data":{"definition":"This group of commands implements nestable conditional blocks. A conditional block must begin with an \\if and end with an \\endif . In between there may be any number of \\elif clauses, which may optionally be followed by a single \\else clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block. The \\if and \\elif commands read their argument(s) and evaluate them as a Boolean expression. If the expression yields true then processing continues normally; otherwise, lines are skipped until a matching \\elif , \\else , or \\endif is reached. Once an \\if or \\elif test has succeeded, the arguments of later \\elif commands in the same block are not evaluated but are treated as false. Lines following an \\else are processed only if no earlier matching \\if or \\elif succeeded. The expression argument of an \\if or \\elif command is subject to variable interpolation and backquote expansion, just like any other backslash command argument. After that it is evaluated like the value of an on/off option variable. So a valid value is any unambiguous case-insensitive match for one of: true , false , 1 , 0 , on , off , yes , no . For example, t , T , and tR will all be considered to be true . Expressions that do not properly evaluate to true or false will generate a warning and be treated as false. Lines being skipped are parsed normally to identify queries and backslash commands, but queries are not sent to the server, and backslash commands other than conditionals ( \\if , \\elif , \\else , \\endif ) are ignored. Conditional commands are checked only for valid nesting. Variable references in skipped lines are not expanded, and backquote expansion is not performed either. All the backslash commands of a given conditional block must appear in the same source file. If EOF is reached on the main input file or an \\include -ed file before all local \\if -blocks have been closed, then psql will raise an error. Here is an example: -- check for the existence of two separate records in the database and store -- the results in separate psql variables SELECT EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer, EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee \\gset \\if :is_customer SELECT * FROM customer WHERE customer_id = 123; \\elif :is_employee \\echo 'is not a customer but is an employee' SELECT * FROM employee WHERE employee_id = 456; \\else \\if yes \\echo 'not a customer or employee' \\else \\echo 'this will never print' \\endif \\endif","modifiers":[],"signature":"\\if expression \\elif expression \\else \\endif","spellings":["\\if","\\elif","\\else","\\endif"]},"comparison_hash":"8ce3164f0726c6db12fcfde01f634f006acec0974c0cbadae292d925e62cd49a","description":["This group of commands implements nestable conditional blocks. A conditional block must begin with an \\if and end with an \\endif . In between there may be any number of \\elif clauses, which may optionally be followed by a single \\else clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block."],"description_zh":"这组命令实现了可嵌套的条件块。条件块必须以 \\if 开始，并以 \\endif 结束。在两者之间可以有任意数量的 \\elif 子句，后面可以选择性地跟着一个 \\else 子句。在形成条件块的命令之间通常会出现普通查询和其他类型的反斜线命令。","description_zh_html":"\u003cdd\u003e\u003cp\u003e\n        这组命令实现了可嵌套的条件块。条件块必须以\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e 开始，并以\u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e 结束。在两者之间可以有任意数量的\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 子句，后面可以选择性地跟着一个\u003ccode class=\"command\"\u003e\\else\u003c/code\u003e 子句。在形成条件块的命令之间通常会出现普通查询和其他类型的反斜线命令。\n        \u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e 和\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 命令读取其参数，并将其作为布尔表达式求值。如果表达式的值为 \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e，则正常继续处理；否则，跳过后续行，直到遇到匹配的\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e、\u003ccode class=\"command\"\u003e\\else\u003c/code\u003e 或\u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e。一旦\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e 或\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 测试成功，同一块中后续\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 命令的参数就不再求值，而是被视为假。只有前面所有匹配的\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e 和\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 测试都未成功时，才会处理\u003ccode class=\"command\"\u003e\\else\u003c/code\u003e 后面的行。\n\u003c/p\u003e\u003cp\u003e\n        与其他反斜线命令的参数一样，\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e 或\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 命令的 \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e 参数会经过变量插值和反引号扩展。随后，按开/关选项变量值的规则对结果求值。因此，有效值是以下值的不区分大小写且无歧义的匹配：\u003ccode class=\"literal\"\u003etrue\u003c/code\u003e、\u003ccode class=\"literal\"\u003efalse\u003c/code\u003e、\u003ccode class=\"literal\"\u003e1\u003c/code\u003e、\u003ccode class=\"literal\"\u003e0\u003c/code\u003e、\u003ccode class=\"literal\"\u003eon\u003c/code\u003e、\u003ccode class=\"literal\"\u003eoff\u003c/code\u003e、\u003ccode class=\"literal\"\u003eyes\u003c/code\u003e、\u003ccode class=\"literal\"\u003eno\u003c/code\u003e。例如，\u003ccode class=\"literal\"\u003et\u003c/code\u003e、\u003ccode class=\"literal\"\u003eT\u003c/code\u003e 和 \u003ccode class=\"literal\"\u003etR\u003c/code\u003e 都会被视为 \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e。\n        \u003c/p\u003e\u003cp\u003e\n        不能正确求值为真或假的表达式会产生警告，并被视为假。\n        \u003c/p\u003e\u003cp\u003e\n        被跳过的行会被正常解析以识别查询和反斜线命令，但查询不会发送到服务器，而且除了条件命令（\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e、\u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e、\u003ccode class=\"command\"\u003e\\else\u003c/code\u003e、\u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e）之外的反斜线命令会被忽略。仅检查跳过行中条件命令的有效嵌套。跳过行中的变量引用不会被展开，也不会执行反引号扩展。\n        \u003c/p\u003e\u003cp\u003e\n        同一个条件块的所有反斜线命令必须出现在同一个源文件中。如果主输入文件或通过\u003ccode class=\"command\"\u003e\\include\u003c/code\u003e 引入的文件到达 EOF 时，仍有本地\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e 块未关闭，\u003cspan class=\"application\"\u003epsql\u003c/span\u003e 就会报错。\n        \u003c/p\u003e\u003cp\u003e\n         下面是一个示例：\n        \u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\n-- 检查数据库中是否存在两条不同的记录，并将\n-- 结果分别存入不同的 psql 变量\nSELECT\n    EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,\n    EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee\n\\gset\n\\if :is_customer\n    SELECT * FROM customer WHERE customer_id = 123;\n\\elif :is_employee\n    \\echo 'is not a customer but is an employee'\n    SELECT * FROM employee WHERE employee_id = 456;\n\\else\n    \\if yes\n        \\echo 'not a customer or employee'\n    \\else\n        \\echo 'this will never print'\n    \\endif\n\\endif\n\u003c/pre\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":"\\else"}],"facts_zh":[{"label":"客户端","value":"psql 18.7"},{"label":"区分大小写的写法","value":"\\else"}],"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=\"PSQL-METACOMMAND-IF\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\if\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\elif\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\else\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\endif\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        This group of commands implements nestable conditional blocks.\n        A conditional block must begin with an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and end\n        with an \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e.  In between there may be any number\n        of \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e clauses, which may optionally be followed\n        by a single \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e clause.  Ordinary queries and\n        other types of backslash commands may (and usually do) appear between\n        the commands forming a conditional block.\n        \u003c/p\u003e\u003cp\u003e\n        The \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands read\n        their argument(s) and evaluate them as a Boolean expression.  If the\n        expression yields \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e then processing continues\n        normally; otherwise, lines are skipped until a\n        matching \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e,\n        or \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e is reached.  Once\n        an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e test has\n        succeeded, the arguments of later \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands in\n        the same block are not evaluated but are treated as false.  Lines\n        following an \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e are processed only if no earlier\n        matching \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e succeeded.\n        \u003c/p\u003e\u003cp\u003e\n        The \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e argument\n        of an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e command\n        is subject to variable interpolation and backquote expansion, just\n        like any other backslash command argument.  After that it is evaluated\n        like the value of an on/off option variable.  So a valid value\n        is any unambiguous case-insensitive match for one of:\n        \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e, \u003ccode class=\"literal\"\u003e1\u003c/code\u003e,\n        \u003ccode class=\"literal\"\u003e0\u003c/code\u003e, \u003ccode class=\"literal\"\u003eon\u003c/code\u003e, \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e,\n        \u003ccode class=\"literal\"\u003eyes\u003c/code\u003e, \u003ccode class=\"literal\"\u003eno\u003c/code\u003e.  For example,\n        \u003ccode class=\"literal\"\u003et\u003c/code\u003e, \u003ccode class=\"literal\"\u003eT\u003c/code\u003e, and \u003ccode class=\"literal\"\u003etR\u003c/code\u003e\n        will all be considered to be \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\n        \u003c/p\u003e\u003cp\u003e\n        Expressions that do not properly evaluate to true or false will\n        generate a warning and be treated as false.\n        \u003c/p\u003e\u003cp\u003e\n        Lines being skipped are parsed normally to identify queries and\n        backslash commands, but queries are not sent to the server, and\n        backslash commands other than conditionals\n        (\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e,\n        \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e) are\n        ignored.  Conditional commands are checked only for valid nesting.\n        Variable references in skipped lines are not expanded, and backquote\n        expansion is not performed either.\n        \u003c/p\u003e\u003cp\u003e\n        All the backslash commands of a given conditional block must appear in\n        the same source file. If EOF is reached on the main input file or an\n        \u003ccode class=\"command\"\u003e\\include\u003c/code\u003e-ed file before all local\n        \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e-blocks have been closed,\n        then \u003cspan class=\"application\"\u003epsql\u003c/span\u003e will raise an error.\n        \u003c/p\u003e\u003cp\u003e\n         Here is an example:\n        \u003c/p\u003e\u003cpre class=\"programlisting\"\u003e-- check for the existence of two separate records in the database and store\n-- the results in separate psql variables\nSELECT\n    EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,\n    EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee\n\\gset\n\\if :is_customer\n    SELECT * FROM customer WHERE customer_id = 123;\n\\elif :is_employee\n    \\echo 'is not a customer but is an employee'\n    SELECT * FROM employee WHERE employee_id = 456;\n\\else\n    \\if yes\n        \\echo 'not a customer or employee'\n    \\else\n        \\echo 'this will never print'\n    \\endif\n\\endif\n\u003c/pre\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","manual_path":"app-psql.html#PSQL-METACOMMAND-IF","modifiers":[],"related":[{"label":"\\if","url":"/wiki/psql/cmd-69-66/?v=18"},{"label":"\\elif","url":"/wiki/psql/cmd-65-6c-69-66/?v=18"},{"label":"\\endif","url":"/wiki/psql/cmd-65-6e-64-69-66/?v=18"},{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"related_zh":[{"label":"\\if","url":"/wiki/psql/cmd-69-66/?v=18"},{"label":"\\elif","url":"/wiki/psql/cmd-65-6c-69-66/?v=18"},{"label":"\\endif","url":"/wiki/psql/cmd-65-6e-64-69-66/?v=18"},{"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":"\\if expression \\elif expression \\else \\endif","sources":[{"anchor":"PSQL-METACOMMAND-IF","file":"app-psql.html","label":"18.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","url":"/docs/18/app-psql.html#PSQL-METACOMMAND-IF"}],"spellings":["\\if","\\elif","\\else","\\endif"],"tables":[{"columns":[{"key":"command","label":"Command"},{"key":"modifiers","label":"Documented suffix modifiers"}],"key":"spellings","rows":[{"command":{"text":"\\if","url":"/wiki/psql/cmd-69-66/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\elif","url":"/wiki/psql/cmd-65-6c-69-66/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\else","url":"/wiki/psql/cmd-65-6c-73-65/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\endif","url":"/wiki/psql/cmd-65-6e-64-69-66/?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":"\\if","url":"/wiki/psql/cmd-69-66/?v=18"},"modifiers":"此语法签名未列出"},{"command":{"text":"\\elif","url":"/wiki/psql/cmd-65-6c-69-66/?v=18"},"modifiers":"此语法签名未列出"},{"command":{"text":"\\else","url":"/wiki/psql/cmd-65-6c-73-65/?v=18"},"modifiers":"此语法签名未列出"},{"command":{"text":"\\endif","url":"/wiki/psql/cmd-65-6e-64-69-66/?v=18"},"modifiers":"此语法签名未列出"}],"title":"本版手册中的写法"}],"zh_from":"same-version-manual"},"ManualEvidence":{"manual_path":"app-psql.html#PSQL-METACOMMAND-IF","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":"PSQL-METACOMMAND-IF","file":"app-psql.html","label":"18.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","url":"/docs/18/app-psql.html#PSQL-METACOMMAND-IF"}]},"MeasuredEvidence":{}},"Text":{"Collection":"psql","Key":"cmd-65-6c-73-65","SourceDatabase":"center","Version":"18","Locale":"en","Title":"\\else","Summary":"This group of commands implements nestable conditional blocks. A conditional block must begin with an \\if and end with an \\endif . In between there may be any number of \\elif clauses, which may optionally be followed by a single \\else clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block.","BodyHTML":"\u003cdiv\u003e\u003cdl\u003e\u003cdt id=\"PSQL-METACOMMAND-IF\"\u003e\u003cspan\u003e\u003ccode\u003e\\if\u003c/code\u003e \u003cem\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e\\elif\u003c/code\u003e \u003cem\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e\\else\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e\\endif\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        This group of commands implements nestable conditional blocks.\n        A conditional block must begin with an \u003ccode\u003e\\if\u003c/code\u003e and end\n        with an \u003ccode\u003e\\endif\u003c/code\u003e.  In between there may be any number\n        of \u003ccode\u003e\\elif\u003c/code\u003e clauses, which may optionally be followed\n        by a single \u003ccode\u003e\\else\u003c/code\u003e clause.  Ordinary queries and\n        other types of backslash commands may (and usually do) appear between\n        the commands forming a conditional block.\n        \u003c/p\u003e\u003cp\u003e\n        The \u003ccode\u003e\\if\u003c/code\u003e and \u003ccode\u003e\\elif\u003c/code\u003e commands read\n        their argument(s) and evaluate them as a Boolean expression.  If the\n        expression yields \u003ccode\u003etrue\u003c/code\u003e then processing continues\n        normally; otherwise, lines are skipped until a\n        matching \u003ccode\u003e\\elif\u003c/code\u003e, \u003ccode\u003e\\else\u003c/code\u003e,\n        or \u003ccode\u003e\\endif\u003c/code\u003e is reached.  Once\n        an \u003ccode\u003e\\if\u003c/code\u003e or \u003ccode\u003e\\elif\u003c/code\u003e test has\n        succeeded, the arguments of later \u003ccode\u003e\\elif\u003c/code\u003e commands in\n        the same block are not evaluated but are treated as false.  Lines\n        following an \u003ccode\u003e\\else\u003c/code\u003e are processed only if no earlier\n        matching \u003ccode\u003e\\if\u003c/code\u003e or \u003ccode\u003e\\elif\u003c/code\u003e succeeded.\n        \u003c/p\u003e\u003cp\u003e\n        The \u003cem\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e argument\n        of an \u003ccode\u003e\\if\u003c/code\u003e or \u003ccode\u003e\\elif\u003c/code\u003e command\n        is subject to variable interpolation and backquote expansion, just\n        like any other backslash command argument.  After that it is evaluated\n        like the value of an on/off option variable.  So a valid value\n        is any unambiguous case-insensitive match for one of:\n        \u003ccode\u003etrue\u003c/code\u003e, \u003ccode\u003efalse\u003c/code\u003e, \u003ccode\u003e1\u003c/code\u003e,\n        \u003ccode\u003e0\u003c/code\u003e, \u003ccode\u003eon\u003c/code\u003e, \u003ccode\u003eoff\u003c/code\u003e,\n        \u003ccode\u003eyes\u003c/code\u003e, \u003ccode\u003eno\u003c/code\u003e.  For example,\n        \u003ccode\u003et\u003c/code\u003e, \u003ccode\u003eT\u003c/code\u003e, and \u003ccode\u003etR\u003c/code\u003e\n        will all be considered to be \u003ccode\u003etrue\u003c/code\u003e.\n        \u003c/p\u003e\u003cp\u003e\n        Expressions that do not properly evaluate to true or false will\n        generate a warning and be treated as false.\n        \u003c/p\u003e\u003cp\u003e\n        Lines being skipped are parsed normally to identify queries and\n        backslash commands, but queries are not sent to the server, and\n        backslash commands other than conditionals\n        (\u003ccode\u003e\\if\u003c/code\u003e, \u003ccode\u003e\\elif\u003c/code\u003e,\n        \u003ccode\u003e\\else\u003c/code\u003e, \u003ccode\u003e\\endif\u003c/code\u003e) are\n        ignored.  Conditional commands are checked only for valid nesting.\n        Variable references in skipped lines are not expanded, and backquote\n        expansion is not performed either.\n        \u003c/p\u003e\u003cp\u003e\n        All the backslash commands of a given conditional block must appear in\n        the same source file. If EOF is reached on the main input file or an\n        \u003ccode\u003e\\include\u003c/code\u003e-ed file before all local\n        \u003ccode\u003e\\if\u003c/code\u003e-blocks have been closed,\n        then \u003cspan\u003epsql\u003c/span\u003e will raise an error.\n        \u003c/p\u003e\u003cp\u003e\n         Here is an example:\n        \u003c/p\u003e\u003cpre\u003e-- check for the existence of two separate records in the database and store\n-- the results in separate psql variables\nSELECT\n    EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,\n    EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee\n\\gset\n\\if :is_customer\n    SELECT * FROM customer WHERE customer_id = 123;\n\\elif :is_employee\n    \\echo \u0026#39;is not a customer but is an employee\u0026#39;\n    SELECT * FROM employee WHERE employee_id = 456;\n\\else\n    \\if yes\n        \\echo \u0026#39;not a customer or employee\u0026#39;\n    \\else\n        \\echo \u0026#39;this will never print\u0026#39;\n    \\endif\n\\endif\n\u003c/pre\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","SourceRevision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","ContentHash":"3b748947783c0c3882650b0ac15f87419d39c6b21e503b384790e01fb5bb00cd","Payload":{"description":["This group of commands implements nestable conditional blocks. A conditional block must begin with an \\if and end with an \\endif . In between there may be any number of \\elif clauses, which may optionally be followed by a single \\else clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block."],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"PSQL-METACOMMAND-IF\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\if\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\elif\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\else\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\endif\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        This group of commands implements nestable conditional blocks.\n        A conditional block must begin with an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and end\n        with an \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e.  In between there may be any number\n        of \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e clauses, which may optionally be followed\n        by a single \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e clause.  Ordinary queries and\n        other types of backslash commands may (and usually do) appear between\n        the commands forming a conditional block.\n        \u003c/p\u003e\u003cp\u003e\n        The \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands read\n        their argument(s) and evaluate them as a Boolean expression.  If the\n        expression yields \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e then processing continues\n        normally; otherwise, lines are skipped until a\n        matching \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e,\n        or \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e is reached.  Once\n        an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e test has\n        succeeded, the arguments of later \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands in\n        the same block are not evaluated but are treated as false.  Lines\n        following an \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e are processed only if no earlier\n        matching \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e succeeded.\n        \u003c/p\u003e\u003cp\u003e\n        The \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e argument\n        of an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e command\n        is subject to variable interpolation and backquote expansion, just\n        like any other backslash command argument.  After that it is evaluated\n        like the value of an on/off option variable.  So a valid value\n        is any unambiguous case-insensitive match for one of:\n        \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e, \u003ccode class=\"literal\"\u003e1\u003c/code\u003e,\n        \u003ccode class=\"literal\"\u003e0\u003c/code\u003e, \u003ccode class=\"literal\"\u003eon\u003c/code\u003e, \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e,\n        \u003ccode class=\"literal\"\u003eyes\u003c/code\u003e, \u003ccode class=\"literal\"\u003eno\u003c/code\u003e.  For example,\n        \u003ccode class=\"literal\"\u003et\u003c/code\u003e, \u003ccode class=\"literal\"\u003eT\u003c/code\u003e, and \u003ccode class=\"literal\"\u003etR\u003c/code\u003e\n        will all be considered to be \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\n        \u003c/p\u003e\u003cp\u003e\n        Expressions that do not properly evaluate to true or false will\n        generate a warning and be treated as false.\n        \u003c/p\u003e\u003cp\u003e\n        Lines being skipped are parsed normally to identify queries and\n        backslash commands, but queries are not sent to the server, and\n        backslash commands other than conditionals\n        (\u003ccode class=\"command\"\u003e\\if\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e,\n        \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e) are\n        ignored.  Conditional commands are checked only for valid nesting.\n        Variable references in skipped lines are not expanded, and backquote\n        expansion is not performed either.\n        \u003c/p\u003e\u003cp\u003e\n        All the backslash commands of a given conditional block must appear in\n        the same source file. If EOF is reached on the main input file or an\n        \u003ccode class=\"command\"\u003e\\include\u003c/code\u003e-ed file before all local\n        \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e-blocks have been closed,\n        then \u003cspan class=\"application\"\u003epsql\u003c/span\u003e will raise an error.\n        \u003c/p\u003e\u003cp\u003e\n         Here is an example:\n        \u003c/p\u003e\u003cpre class=\"programlisting\"\u003e-- check for the existence of two separate records in the database and store\n-- the results in separate psql variables\nSELECT\n    EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,\n    EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee\n\\gset\n\\if :is_customer\n    SELECT * FROM customer WHERE customer_id = 123;\n\\elif :is_employee\n    \\echo 'is not a customer but is an employee'\n    SELECT * FROM employee WHERE employee_id = 456;\n\\else\n    \\if yes\n        \\echo 'not a customer or employee'\n    \\else\n        \\echo 'this will never print'\n    \\endif\n\\endif\n\u003c/pre\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","related":[{"label":"\\if","url":"/wiki/psql/cmd-69-66/?v=18"},{"label":"\\elif","url":"/wiki/psql/cmd-65-6c-69-66/?v=18"},{"label":"\\endif","url":"/wiki/psql/cmd-65-6e-64-69-66/?v=18"},{"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":"\\if","url":"/wiki/psql/cmd-69-66/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\elif","url":"/wiki/psql/cmd-65-6c-69-66/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\else","url":"/wiki/psql/cmd-65-6c-73-65/?v=18"},"modifiers":"None listed in this signature"},{"command":{"text":"\\endif","url":"/wiki/psql/cmd-65-6e-64-69-66/?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":"\\if","Signature":"\\if expression \\elif expression \\else \\endif","Modifiers":[]},{"Version":"18","Ordinal":1,"Command":"\\elif","Signature":"\\if expression \\elif expression \\else \\endif","Modifiers":[]},{"Version":"18","Ordinal":2,"Command":"\\else","Signature":"\\if expression \\elif expression \\else \\endif","Modifiers":[]},{"Version":"18","Ordinal":3,"Command":"\\endif","Signature":"\\if expression \\elif expression \\else \\endif","Modifiers":[]}],"SQLState":null,"Evidence":null}
