下载
准备
sudo yum install postgresql-devel.x86_64
编译
git clone https://github.com/okbob/plpgsql_check.git
cd plpgsql_check
```bash
git checkout v2.7.9
make PG_CONFIG=$DB14_17_HOME/bin/pg_config
sudo make PG_CONFIG=$DB14_17_HOME/bin/pg_config install
[postgres@localhost plpgsql_check]$ sudo make PG_CONFIG=$DB14_17_HOME/bin/pg_config install
/usr/bin/mkdir -p '/usr/local/postgres/14.17/lib'
/usr/bin/mkdir -p '/usr/local/postgres/14.17/share/extension'
/usr/bin/mkdir -p '/usr/local/postgres/14.17/share/extension'
/usr/bin/install -c -m 755 plpgsql_check.so '/usr/local/postgres/14.17/lib/plpgsql_check.so'
/usr/bin/install -c -m 644 .//plpgsql_check.control '/usr/local/postgres/14.17/share/extension/'
/usr/bin/install -c -m 644 .//plpgsql_check--2.7.sql '/usr/local/postgres/14.17/share/extension/'
# 使用
```sql
CREATE EXTENSION plpgsql_check;
ERROR: could not open extension control file "/usr/local/postgres/14.17/share/extension/plpgsql_check.control": No such file or directory
-- 创建测试函数
CREATE OR REPLACE FUNCTION test_func() RETURNS void AS $$
BEGIN
SELECT 1/0; -- 故意制造错误
END;
$$ LANGUAGE plpgsql;
-- 运行静态检查
SELECT * FROM plpgsql_check_function('test_func()'); -- 应返回除零错误警告
卸载
DROP EXTENSION IF EXISTS plpgsql_check CASCADE;
sudo rm /usr/local/postgres/14.17/lib/plpgsql_check.so
sudo rm /usr/local/postgres/14.17/share/extension/plpgsql_check--2.7.sql
sudo rm /usr/local/postgres/14.17/share/extension/plpgsql_check.control