我在Postgres中有一些大的varchar值,我想要SELECT并移动到其他地方.他们要去的地方使用VARCHAR(4095)所以我只需要最多4095个字节(我认为是字节),其中一些变量非常大,所以性能优化就是选择它们的截断版本.
我怎样才能做到这一点?
就像是:
SELECT TruncATED(my_val,4095) ...
解决方法
varchar(n)中的n是字符数(不是字节数).
The documentation:
sql defines two primary character types:
character varying(n)
and
character(n)
,wheren
is a positive integer. Both of these types can
store strings up ton
characters (not bytes) in length.
大胆强调我的.
SELECT left(my_val,4095)
或者你可以只是cast:
SELECT my_val::varchar(4095)
If one explicitly casts a value to
character varying(n)
or
character(n)
,then an over-length value will be truncated ton
characters without raising an error. (This too is required by the sql standard.)
原文地址:https://www.jb51.cc/mssql/75734.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。