How to limit the maximum display length of a column in PostgreSQL

随声附和 提交于 2021-02-18 10:25:32

问题


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.

Something like:

   select longcolumn (only 10 chars) from mytable;

How would I do this?


回答1:


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;



回答2:


Slightly shorter:

SELECT left(longcolumn, 10) from mytable;


来源:https://stackoverflow.com/questions/16464468/how-to-limit-the-maximum-display-length-of-a-column-in-postgresql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!