小编Cyr*_*amm的帖子

Postgres 铸造复合类型

在 Postgres 9.6 中使用函数转换为复合类型时,我遇到了一个奇怪的行为。

我已将复合类型“向量”声明为 x,y,z - 每个双精度以及如下强制转换:

create type vector as(
 x double precision,
 y double precision,
 z double precision
);

create cast (text as vector)
 with function vector_from_text(text) as implicit;
Run Code Online (Sandbox Code Playgroud)

函数 vector_from_text 看起来像这样:

create or replace function vector_from_text(text, out result vector) strict immutable language plpgsql as $$
declare
    d double precision[];
begin
    result := null;
    if ($1 is null) then
        return;
    end if;

    begin
        with c1 as (
               select $1::jsonb src
        )
        select row((src->>'x')::double precision, (src->>'y')::double precision, (src->>'z')::double …
Run Code Online (Sandbox Code Playgroud)

postgresql types casting composite

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

标签 统计

casting ×1

composite ×1

postgresql ×1

types ×1