PostgreSQL中如何限制列的最大显示长度 [英] How to limit the maximum display length of a column in PostgreSQL

查看:73
本文介绍了PostgreSQL中如何限制列的最大显示长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PostgreSQL,并且我在表中有一个包含很长文本的列.我想在查询中选择此列,但限制其显示长度.

I am using PostgreSQL, and I have a column in a table which contains very long text. I want to select this column in a query, but limit its display length.

类似于:

   select longcolumn (only 10 chars) from mytable;

我该怎么做?

推荐答案

你能做的就是使用 PostgreSQL 的 substring() 方法.以下两个命令中的任何一个都可以使用:

What you can do is use PostgreSQL's substring() method. Either one of the two commands below will work:

SELECT substring(longcolumn for 10) FROM mytable;
SELECT substring(longcolumn from 1 for 10) FROM mytable;

这篇关于PostgreSQL中如何限制列的最大显示长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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