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

后端 未结 2 1846
北恋
北恋 2021-02-20 07:31

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 lik

相关标签:
2条回答
  • 2021-02-20 08:32

    Slightly shorter:

    SELECT left(longcolumn, 10) from mytable;
    
    0 讨论(0)
  • 2021-02-20 08:36

    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;
    
    0 讨论(0)
提交回复
热议问题