2021-08-28 14:13:37 +03:00
|
|
|
================================================================================
|
|
|
|
basic
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if true then select 1; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(true)
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(number)))))
|
|
|
|
(dollar_quote))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
many statements
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if true then select 1; select 2; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(true)
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(number)))
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(number)))))
|
|
|
|
(dollar_quote))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
if then else
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if var <> 5 then return 1; else return 2; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_op)
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))))
|
|
|
|
(dollar_quote))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
if then else if
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if var > 5 then return 1; elsif var = 4 then return 2; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_op)
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_op)
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))))
|
|
|
|
(dollar_quote))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
elseif/elsif
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if var > 5 then return 1; elsif var = 4 then return 2; elseif var = 3 then return 3; else return 4; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_op)
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_op)
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_op)
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number))))
|
|
|
|
(dollar_quote))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
nested
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if true then return 1; else if var = 4 then return 2; end if; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(true)
|
|
|
|
(return_statement
|
|
|
|
(number))
|
|
|
|
(if_statement
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_op)
|
|
|
|
(number))
|
|
|
|
(return_statement
|
|
|
|
(number)))))
|
|
|
|
(dollar_quote))))
|
2021-08-31 21:28:25 +03:00
|
|
|
|
|
|
|
================================================================================
|
|
|
|
if is not null
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if foo is not null then select 1; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_null))
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(number)))))
|
|
|
|
(dollar_quote))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
if is not distinct from
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if foo is not distinct from bar then select 1; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_kw)
|
|
|
|
(identifier))
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(number)))))
|
|
|
|
(dollar_quote))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
if is distinct from
|
|
|
|
================================================================================
|
|
|
|
do $$ begin
|
|
|
|
if foo is distinct from bar then select 1; end if;
|
|
|
|
end $$;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(do_block
|
|
|
|
(block
|
|
|
|
(dollar_quote)
|
|
|
|
(body
|
|
|
|
(if_statement
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_kw)
|
|
|
|
(identifier))
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(number)))))
|
|
|
|
(dollar_quote))))
|