在 postgresql 断言消息中包含参数
Include parameters in posgresql assert message
有没有办法在 PostgreSQL ASSERT 消息中包含参数。
示例:
do $$
declare
c integer;
begin
c := (select count(*) from pg_database);
assert c = 7, 'not 7!';
assert c = 8, 'not 8!';
assert c = 5, ('% not 5!' , c);
end;$$;
这个有效:
assert c = 8, 'not 8!';
这个断言:
assert c = 5, ('% not 5!' , c);
按应有的方式显示错误消息:
SQL Error [P0004]: ERROR: ("% not 5!",7)
Where: PL/pgSQL function inline_code_block line 7 at ASSERT
ERROR: ("% not 5!",7)
Where: PL/pgSQL function inline_code_block line 7 at ASSERT
ERROR: ("% not 5!",7)
Where: PL/pgSQL function inline_code_block line 7 at ASSERT
但变量没有替换文本中的 %。
使用FORMAT:
ASSERT c = 5, FORMAT('%s not 5!', c);
有没有办法在 PostgreSQL ASSERT 消息中包含参数。
示例:
do $$
declare
c integer;
begin
c := (select count(*) from pg_database);
assert c = 7, 'not 7!';
assert c = 8, 'not 8!';
assert c = 5, ('% not 5!' , c);
end;$$;
这个有效:
assert c = 8, 'not 8!';
这个断言:
assert c = 5, ('% not 5!' , c);
按应有的方式显示错误消息:
SQL Error [P0004]: ERROR: ("% not 5!",7)
Where: PL/pgSQL function inline_code_block line 7 at ASSERT
ERROR: ("% not 5!",7)
Where: PL/pgSQL function inline_code_block line 7 at ASSERT
ERROR: ("% not 5!",7)
Where: PL/pgSQL function inline_code_block line 7 at ASSERT
但变量没有替换文本中的 %。
使用FORMAT:
ASSERT c = 5, FORMAT('%s not 5!', c);