问题
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