src/bin/psql/command.c
static backslashResult
exec_command_if(PsqlScanState scan_state, ConditionalStack cstack,
				PQExpBuffer query_buf)
{
	if (conditional_active(cstack))
	{
		/*
		 * First, push a new active stack entry; this ensures that the lexer
		 * will perform variable substitution and backtick evaluation while
		 * scanning the expression.  (That should happen anyway, since we know
		 * we're in an active outer branch, but let's be sure.)
		 */
		conditional_stack_push(cstack, IFSTATE_TRUE);

		/* Remember current query state in case we need to restore later */
		save_query_text_state(scan_state, cstack, query_buf);

		/*
		 * Evaluate the expression; if it's false, change to inactive state.
		 */
		if (!is_true_boolean_expression(scan_state, "\\if expression"))
			conditional_stack_poke(cstack, IFSTATE_FALSE);
	}
	else
	{
		/*
		 * We're within an inactive outer branch, so this entire \if block
		 * will be ignored.  We don't want to evaluate the expression, so push
		 * the "ignored" stack state before scanning it.
		 */
		conditional_stack_push(cstack, IFSTATE_IGNORED);

		/* Remember current query state in case we need to restore later */
		save_query_text_state(scan_state, cstack, query_buf);

		ignore_boolean_expression(scan_state);
	}

	return PSQL_CMD_SKIP_LINE;
}
/*
 * \if <expr> -- beginning of an \if..\endif block
 *
 * <expr> is parsed as a boolean expression.  Invalid expressions will emit a
 * warning and be treated as false.  Statements that follow a false expression
 * will be parsed but ignored.  Note that in the case where an \if statement
 * is itself within an inactive section of a block, then the entire inner
 * \if..\endif block will be parsed but ignored.
 */
\if  -- beginning of an \if..\endif block
 is parsed as a boolean expression.  Invalid expressions will emit a
warning and be treated as false.  Statements that follow a false expression
will be parsed but ignored.  Note that in the case where an \if statement
is itself within an inactive section of a block, then the entire inner
\if..\endif block will be parsed but ignored.
\ if -- beginning of an \ if .. \ endif block is parsed as a boolean expression . Invalid expressions will emit a warning and be treated as false . Statements that follow a false expression will be parsed but ignored . Note that in the case where an \ if statement is itself within an inactive section of a block then the entire inner \ if .. \ endif block will be parsed but ignored .
static backslashResult
exec_command_if(PsqlScanState scan_state, ConditionalStack cstack,
				PQExpBuffer query_buf)
{
	if (conditional_active(cstack))
	{
		conditional_stack_push(cstack, IFSTATE_TRUE);
		save_query_text_state(scan_state, cstack, query_buf);
		if (!is_true_boolean_expression(scan_state, "\\if expression"))
			conditional_stack_poke(cstack, IFSTATE_FALSE);
	}
	else
	{
		conditional_stack_push(cstack, IFSTATE_IGNORED);
		save_query_text_state(scan_state, cstack, query_buf);
		ignore_boolean_expression(scan_state);
	}
	return PSQL_CMD_SKIP_LINE;
}
static backslashResult exec_command_if ( PsqlScanState scan_state , ConditionalStack cstack , PQExpBuffer query_buf ) { if ( conditional_active ( cstack ) ) { conditional_stack_push ( cstack , IFSTATE_TRUE ) ; save_query_text_state ( scan_state , cstack , query_buf ) ; if ( ! is_true_boolean_expression ( scan_state , " \\ " ) ) conditional_stack_poke ( cstack , IFSTATE_FALSE ) ; } else { conditional_stack_push ( cstack , IFSTATE_IGNORED ) ; save_query_text_state ( scan_state , cstack , query_buf ) ; ignore_boolean_expression ( scan_state ) ; } return PSQL_CMD_SKIP_LINE ; }
\if <expr> -- beginning of an \if..\endif block
 <expr> is parsed as a boolean expression.
\ if <expr > -- beginning of an \ if .. \ endif block <expr > is parsed as a boolean expression .
/*
		 * First, push a new active stack entry; this ensures that the lexer
		 * will perform variable substitution and backtick evaluation while
		 * scanning the expression.  (That should happen anyway, since we know
		 * we're in an active outer branch, but let's be sure.)
		 */ /* Remember current query state in case we need to restore later */ /*
		 * Evaluate the expression; if it's false, change to inactive state.
		 */ /*
		 * We're within an inactive outer branch, so this entire \if block
		 * will be ignored.  We don't want to evaluate the expression, so push
		 * the "ignored" stack state before scanning it.
		 */ /* Remember current query state in case we need to restore later */