{"Entry":{"collection":"psql","key":"cmd-65-6e-64-69-66","name":"\\endif","aliases":["\\endif"],"metadata":{"aliases":["\\endif"],"category":"Scripting and assistance","content_hash":"49fb7d4f694a21abe2082d461cbe0083c6166ecfcea6c1da21a9f58c2e2e7072","imported_at":"2026-09-30T00:40:44.995389+08:00","name":"\\endif","name_zh":"","slug":"cmd-65-6e-64-69-66","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-6e-64-69-66","SourceDatabase":"center","Version":"18","SourceTable":"psql_command","SourceKey":"cmd-65-6e-64-69-66","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"command":"\\endif","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."],"facts":[{"label":"Client","value":"psql 18.6"},{"label":"Case-sensitive spelling","value":"\\endif"}],"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\n\u003cp\u003eThis group of commands implements nestable conditional blocks. A conditional block must begin with an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and end with an \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e. In between there may be any number of \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e clauses, which may optionally be followed by a single \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands read their argument(s) and evaluate them as a Boolean expression. If the expression yields \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e then processing continues normally; otherwise, lines are skipped until a matching \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e, or \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e is reached. Once an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e test has succeeded, the arguments of later \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands in the same block are not evaluated but are treated as false. Lines following an \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e are processed only if no earlier matching \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e succeeded.\u003c/p\u003e\n\u003cp\u003eThe \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e argument of an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 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: \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. For example, \u003ccode class=\"literal\"\u003et\u003c/code\u003e, \u003ccode class=\"literal\"\u003eT\u003c/code\u003e, and \u003ccode class=\"literal\"\u003etR\u003c/code\u003e will all be considered to be \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eExpressions that do not properly evaluate to true or false will generate a warning and be treated as false.\u003c/p\u003e\n\u003cp\u003eLines 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 (\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) 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.\u003c/p\u003e\n\u003cp\u003eAll 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 \u003ccode class=\"command\"\u003e\\include\u003c/code\u003e-ed file before all local \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e-blocks have been closed, then \u003cspan class=\"application\"\u003epsql\u003c/span\u003e will raise an error.\u003c/p\u003e\n\u003cp\u003eHere is an example:\u003c/p\u003e\n\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\n\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":"\\else","url":"/wiki/psql/cmd-65-6c-73-65/?v=18"},{"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":"\\if expression \\elif expression \\else \\endif","sources":[{"anchor":"PSQL-METACOMMAND-IF","file":"app-psql.html","label":"18.6 English manual · app-psql.html","sha256":"fa2a1d39294b8854318e82e93f71272c645ed88150ecc2786c28902c3f32782c","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"}]},"ManualEvidence":{"manual_path":"app-psql.html#PSQL-METACOMMAND-IF","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":"PSQL-METACOMMAND-IF","file":"app-psql.html","label":"18.6 English manual · app-psql.html","sha256":"fa2a1d39294b8854318e82e93f71272c645ed88150ecc2786c28902c3f32782c","url":"/docs/18/app-psql.html#PSQL-METACOMMAND-IF"}]},"MeasuredEvidence":{}},"Text":{"Collection":"psql","Key":"cmd-65-6e-64-69-66","SourceDatabase":"center","Version":"18","Locale":"en","Title":"\\endif","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\n\u003cp\u003eThis group of commands implements nestable conditional blocks. A conditional block must begin with an \u003ccode\u003e\\if\u003c/code\u003e and end with an \u003ccode\u003e\\endif\u003c/code\u003e. In between there may be any number of \u003ccode\u003e\\elif\u003c/code\u003e clauses, which may optionally be followed by a single \u003ccode\u003e\\else\u003c/code\u003e clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode\u003e\\if\u003c/code\u003e and \u003ccode\u003e\\elif\u003c/code\u003e commands read their argument(s) and evaluate them as a Boolean expression. If the expression yields \u003ccode\u003etrue\u003c/code\u003e then processing continues normally; otherwise, lines are skipped until a matching \u003ccode\u003e\\elif\u003c/code\u003e, \u003ccode\u003e\\else\u003c/code\u003e, or \u003ccode\u003e\\endif\u003c/code\u003e is reached. Once an \u003ccode\u003e\\if\u003c/code\u003e or \u003ccode\u003e\\elif\u003c/code\u003e test has succeeded, the arguments of later \u003ccode\u003e\\elif\u003c/code\u003e commands in the same block are not evaluated but are treated as false. Lines following an \u003ccode\u003e\\else\u003c/code\u003e are processed only if no earlier matching \u003ccode\u003e\\if\u003c/code\u003e or \u003ccode\u003e\\elif\u003c/code\u003e succeeded.\u003c/p\u003e\n\u003cp\u003eThe \u003cem\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e argument of an \u003ccode\u003e\\if\u003c/code\u003e or \u003ccode\u003e\\elif\u003c/code\u003e 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: \u003ccode\u003etrue\u003c/code\u003e, \u003ccode\u003efalse\u003c/code\u003e, \u003ccode\u003e1\u003c/code\u003e, \u003ccode\u003e0\u003c/code\u003e, \u003ccode\u003eon\u003c/code\u003e, \u003ccode\u003eoff\u003c/code\u003e, \u003ccode\u003eyes\u003c/code\u003e, \u003ccode\u003eno\u003c/code\u003e. For example, \u003ccode\u003et\u003c/code\u003e, \u003ccode\u003eT\u003c/code\u003e, and \u003ccode\u003etR\u003c/code\u003e will all be considered to be \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eExpressions that do not properly evaluate to true or false will generate a warning and be treated as false.\u003c/p\u003e\n\u003cp\u003eLines 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 (\u003ccode\u003e\\if\u003c/code\u003e, \u003ccode\u003e\\elif\u003c/code\u003e, \u003ccode\u003e\\else\u003c/code\u003e, \u003ccode\u003e\\endif\u003c/code\u003e) 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.\u003c/p\u003e\n\u003cp\u003eAll 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 \u003ccode\u003e\\include\u003c/code\u003e-ed file before all local \u003ccode\u003e\\if\u003c/code\u003e-blocks have been closed, then \u003cspan\u003epsql\u003c/span\u003e will raise an error.\u003c/p\u003e\n\u003cp\u003eHere is an example:\u003c/p\u003e\n\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\n\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"6bd1d05e113292106505a5190a44c32710ef2b2dc69a2363f1aac09df94fd3b6","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\n\u003cp\u003eThis group of commands implements nestable conditional blocks. A conditional block must begin with an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and end with an \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e. In between there may be any number of \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e clauses, which may optionally be followed by a single \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e clause. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e and \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands read their argument(s) and evaluate them as a Boolean expression. If the expression yields \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e then processing continues normally; otherwise, lines are skipped until a matching \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e, \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e, or \u003ccode class=\"command\"\u003e\\endif\u003c/code\u003e is reached. Once an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e test has succeeded, the arguments of later \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e commands in the same block are not evaluated but are treated as false. Lines following an \u003ccode class=\"command\"\u003e\\else\u003c/code\u003e are processed only if no earlier matching \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e succeeded.\u003c/p\u003e\n\u003cp\u003eThe \u003cem class=\"replaceable\"\u003e\u003ccode\u003eexpression\u003c/code\u003e\u003c/em\u003e argument of an \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e or \u003ccode class=\"command\"\u003e\\elif\u003c/code\u003e 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: \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. For example, \u003ccode class=\"literal\"\u003et\u003c/code\u003e, \u003ccode class=\"literal\"\u003eT\u003c/code\u003e, and \u003ccode class=\"literal\"\u003etR\u003c/code\u003e will all be considered to be \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eExpressions that do not properly evaluate to true or false will generate a warning and be treated as false.\u003c/p\u003e\n\u003cp\u003eLines 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 (\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) 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.\u003c/p\u003e\n\u003cp\u003eAll 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 \u003ccode class=\"command\"\u003e\\include\u003c/code\u003e-ed file before all local \u003ccode class=\"command\"\u003e\\if\u003c/code\u003e-blocks have been closed, then \u003cspan class=\"application\"\u003epsql\u003c/span\u003e will raise an error.\u003c/p\u003e\n\u003cp\u003eHere is an example:\u003c/p\u003e\n\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\n\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":"\\else","url":"/wiki/psql/cmd-65-6c-73-65/?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":"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":"\\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}
