214 lines
5.7 KiB
Text
214 lines
5.7 KiB
Text
================================================================================
|
|
basic
|
|
================================================================================
|
|
do $$ begin execute 'command'; end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(string)))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
into
|
|
================================================================================
|
|
do $$ begin execute 'command' into var; end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(string)
|
|
(into
|
|
(identifier))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
into strict
|
|
================================================================================
|
|
do $$ begin execute 'command' into strict var; end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(string)
|
|
(into
|
|
(identifier))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
using
|
|
================================================================================
|
|
do $$ begin execute 'command' using 1, foo(bar); end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(string)
|
|
(execute_using
|
|
(number)
|
|
(function_call
|
|
(identifier)
|
|
(identifier)))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
function call
|
|
================================================================================
|
|
do $$ begin execute foo() into strict var using 1; end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(function_call
|
|
(identifier))
|
|
(into
|
|
(identifier))
|
|
(execute_using
|
|
(number))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
string concatenation
|
|
================================================================================
|
|
do $$ begin execute 'foo' || 'bar' into _date; end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(op_expression
|
|
(string)
|
|
(other_op)
|
|
(string))
|
|
(into
|
|
(identifier))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
simple nested dollar quote
|
|
================================================================================
|
|
do $$ begin
|
|
execute format(
|
|
$sql$
|
|
select %1$s,
|
|
select 2,
|
|
$sql$
|
|
, _tbl_name) using bar;
|
|
end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(function_call
|
|
(identifier)
|
|
(dollar_quote_string)
|
|
(identifier))
|
|
(execute_using
|
|
(identifier))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
execute format dollar quote
|
|
================================================================================
|
|
do $$ begin
|
|
execute format(
|
|
$sql$
|
|
update %1$s
|
|
set foo = $1, %2$I = $1
|
|
$sql$
|
|
, _tbl_name) using bar;
|
|
end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(function_call
|
|
(identifier)
|
|
(dollar_quote_string)
|
|
(identifier))
|
|
(execute_using
|
|
(identifier))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
complex
|
|
================================================================================
|
|
do $$ begin
|
|
EXECUTE FORMAT(
|
|
$sql$
|
|
UPDATE %2$s SET new_val = $1
|
|
FROM ( SELECT serial AS _serial, created FROM %1$s ) t1
|
|
$sql$
|
|
, _tbl_name) USING baz, bar;
|
|
end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(function_call
|
|
(identifier)
|
|
(dollar_quote_string)
|
|
(identifier))
|
|
(execute_using
|
|
(identifier)
|
|
(identifier))))
|
|
(dollar_quote))))
|
|
|
|
================================================================================
|
|
complex(1)
|
|
================================================================================
|
|
do $$ begin
|
|
EXECUTE FORMAT($sql$
|
|
foo
|
|
$sql$ , _tbl_name) USING bar.baz;
|
|
end $$;
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(do_block
|
|
(block
|
|
(dollar_quote)
|
|
(body
|
|
(execute_statement
|
|
(function_call
|
|
(identifier)
|
|
(dollar_quote_string)
|
|
(identifier))
|
|
(execute_using
|
|
(identifier))))
|
|
(dollar_quote))))
|