2021-08-28 13:46:32 +03:00
|
|
|
================================================================================
|
|
|
|
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)
|
2021-08-30 21:31:09 +03:00
|
|
|
(execute_using
|
|
|
|
(number)
|
|
|
|
(function_call
|
|
|
|
(identifier)
|
|
|
|
(identifier)))))
|
2021-08-28 13:46:32 +03:00
|
|
|
(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))
|
2021-08-30 21:31:09 +03:00
|
|
|
(execute_using
|
|
|
|
(number))))
|
2021-08-28 13:46:32 +03:00
|
|
|
(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))))
|
2021-08-30 21:31:09 +03:00
|
|
|
|
|
|
|
================================================================================
|
|
|
|
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
|
|
|
|
$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))))
|