pg_try_cast
文本转换失败时返回 NULL 或指定类型的回退值。
仓库
Mazuco/pg_try_cast
https://github.com/Mazuco/pg_try_cast
源码
pg_try_cast-1.0.0.tar.gz
pg_try_cast-1.0.0.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pg_try_cast | 1.0 | FUNC | PostgreSQL | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 4855 | pg_try_cast | 否 | 是 | 否 | 是 | 是 | 是 | - |
Release 1.0.0 installs control/SQL 1.0; META provides.version says 1.0.0. PG16+ required, CI covers 16-18; input types without soft-error support may still raise errors.
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 | 1817161514 | pg_try_cast | - |
| RPM | PIGSTY | 1.0.0 | 1817161514 | pg_try_cast_$v | - |
| DEB | PIGSTY | 1.0.0 | 1817161514 | postgresql-$v-pg-try-cast | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0.0 el8.x86_64.pg18 : pg_try_cast_18 pg_try_cast_18-1.0.0-1PGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg17 : pg_try_cast_17 pg_try_cast_17-1.0.0-1PGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg16 : pg_try_cast_16 pg_try_cast_16-1.0.0-1PGSTY.el8.x86_64.rpm
| N/A | N/A |
| el8.aarch64 | PIGSTY 1.0.0 el8.aarch64.pg18 : pg_try_cast_18 pg_try_cast_18-1.0.0-1PGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg17 : pg_try_cast_17 pg_try_cast_17-1.0.0-1PGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg16 : pg_try_cast_16 pg_try_cast_16-1.0.0-1PGSTY.el8.aarch64.rpm
| N/A | N/A |
| el9.x86_64 | PIGSTY 1.0.0 el9.x86_64.pg18 : pg_try_cast_18 pg_try_cast_18-1.0.0-1PGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg17 : pg_try_cast_17 pg_try_cast_17-1.0.0-1PGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg16 : pg_try_cast_16 pg_try_cast_16-1.0.0-1PGSTY.el9.x86_64.rpm
| N/A | N/A |
| el9.aarch64 | PIGSTY 1.0.0 el9.aarch64.pg18 : pg_try_cast_18 pg_try_cast_18-1.0.0-1PGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg17 : pg_try_cast_17 pg_try_cast_17-1.0.0-1PGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg16 : pg_try_cast_16 pg_try_cast_16-1.0.0-1PGSTY.el9.aarch64.rpm
| N/A | N/A |
| el10.x86_64 | PIGSTY 1.0.0 el10.x86_64.pg18 : pg_try_cast_18 pg_try_cast_18-1.0.0-1PGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg17 : pg_try_cast_17 pg_try_cast_17-1.0.0-1PGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg16 : pg_try_cast_16 pg_try_cast_16-1.0.0-1PGSTY.el10.x86_64.rpm
| N/A | N/A |
| el10.aarch64 | PIGSTY 1.0.0 el10.aarch64.pg18 : pg_try_cast_18 pg_try_cast_18-1.0.0-1PGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg17 : pg_try_cast_17 pg_try_cast_17-1.0.0-1PGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg16 : pg_try_cast_16 pg_try_cast_16-1.0.0-1PGSTY.el10.aarch64.rpm
| N/A | N/A |
| d12.x86_64 | PIGSTY 1.0.0 d12.x86_64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~bookworm_amd64.deb
| N/A | N/A |
| d12.aarch64 | PIGSTY 1.0.0 d12.aarch64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~bookworm_arm64.deb
| N/A | N/A |
| d13.x86_64 | PIGSTY 1.0.0 d13.x86_64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~trixie_amd64.deb
| N/A | N/A |
| d13.aarch64 | PIGSTY 1.0.0 d13.aarch64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~trixie_arm64.deb
| N/A | N/A |
| u22.x86_64 | PIGSTY 1.0.0 u22.x86_64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~jammy_amd64.deb
| N/A | N/A |
| u22.aarch64 | PIGSTY 1.0.0 u22.aarch64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~jammy_arm64.deb
| N/A | N/A |
| u24.x86_64 | PIGSTY 1.0.0 u24.x86_64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~noble_amd64.deb
| N/A | N/A |
| u24.aarch64 | PIGSTY 1.0.0 u24.aarch64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~noble_arm64.deb
| N/A | N/A |
| u26.x86_64 | PIGSTY 1.0.0 u26.x86_64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~resolute_amd64.deb
| PIGSTY 1.0.0 u26.x86_64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~resolute_amd64.deb
| PIGSTY 1.0.0 u26.x86_64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~resolute_amd64.deb
| N/A | N/A |
| u26.aarch64 | PIGSTY 1.0.0 u26.aarch64.pg18 : postgresql-18-pg-try-cast postgresql-18-pg-try-cast_1.0.0-1PGSTY~resolute_arm64.deb
| PIGSTY 1.0.0 u26.aarch64.pg17 : postgresql-17-pg-try-cast postgresql-17-pg-try-cast_1.0.0-1PGSTY~resolute_arm64.deb
| PIGSTY 1.0.0 u26.aarch64.pg16 : postgresql-16-pg-try-cast postgresql-16-pg-try-cast_1.0.0-1PGSTY~resolute_arm64.deb
| N/A | N/A |
构建
您可以使用 pig build 命令构建 pg_try_cast 扩展的 RPM / DEB 包:
安装
您可以直接安装 pg_try_cast 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
使用 pig 或者是 apt/yum/dnf 安装扩展:
安装
pig
dnf
apt
创建扩展:
用法
来源:
pg_try_cast 提供 try_cast 与 try_convert,在受支持的输入转换出错时返回回退值,避免整个查询失败。发布版本 1.0.0 安装的 SQL 版本为 1.0。要求 PostgreSQL 16 或更新版本,上游 CI 覆盖 16–18。扩展可信、可迁移,无需预加载。
核心用法
运行边界
try_cast(value text, fallback anyelement) 的第二个参数同时决定结果类型和出错回退值;try_convert(fallback anyelement, value text) 的参数顺序相反。NULL 输入仍返回 NULL,应为回退值指定明确类型。扩展会检查类型修饰符与域约束。它处理文本输入转换,不涵盖任意原生类型转换。尚未支持软错误机制的输入函数仍可能抛出错误,包括向 regtype 传入格式错误的类型名称。安装文件就绪后,拥有数据库 CREATE 权限的角色可安装此可信扩展。
这个页面对您有帮助吗?
感谢反馈,我们会据此改进这篇文档。
哪里没有解决?(可选)