PostgreSQL - 从函数返回 n 大小的 varchar [英] PostgreSQL - return n-sized varchar from function

查看:46
本文介绍了PostgreSQL - 从函数返回 n 大小的 varchar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在文档中发现的那样:

<块引用>

带括号的类型修饰符(例如,类型的精度字段数字)被 CREATE FUNCTION 丢弃

是否有其他方法可以从 plpgsql 函数返回 varchar(N) 类型?

<小时>

问题更新:

在图片上你可以看到 Name 列被识别为 varchar(128),而 Number 列被识别为非大小的 varchar

f_concat 函数返回:cast(res as varchar(255));

解决方案

您可以通过创建一个

As I found in documentation:

Parenthesized type modifiers (e.g., the precision field for type numeric) are discarded by CREATE FUNCTION

Are there any alternatives to return varchar(N) type from plpgsql function?


question update:

On picture you can see that Name column recognised as varchar(128), however Number column is recognised as nonsized varchar

f_concat function returns: cast(res as varchar(255));

解决方案

You can preserve the type modifier for a function result by creating a domain. Postgres will use the underlying varchar(N) type when sending column descriptions to your client:

这篇关于PostgreSQL - 从函数返回 n 大小的 varchar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆