小编Zol*_*kos的帖子

如果 psql 函数和调用函数中存在则截断

我有以下代码来创建一个函数,web_channel2如果表不为空,则截断表中的所有行:

create or replace function truncate_if_exists(tablename text)
returns void language plpgsql as $$
begin
    select
    from information_schema.tables 
    where table_name = tablename;
    if found then
        execute format('truncate %I', tablename);
    end if;
end $$;
Run Code Online (Sandbox Code Playgroud)

不幸的是我不知道应该如何继续...如何执行该函数?

sql postgresql truncate plpgsql search-path

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

plpgsql ×1

postgresql ×1

search-path ×1

sql ×1

truncate ×1