在psql中显示查询结果时,是否可以设置列的最大宽度? [英] Is there a way to set the max width of a column when displaying query results in psql?

查看:142
本文介绍了在psql中显示查询结果时,是否可以设置列的最大宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是我有一个包含10列的表格。这些列之一是HTML,因此很长。它是如此之长,以至于它会缠绕多行并弄乱原本有用的输出。通常,我会选择除该列以外的所有列。但是,我开始加入另一个表,现在有20列。

The problem I'm having is that I have a table with 10 columns. 1 of those columns is HTML and, as a result, is really long. It's so long that it wraps around several lines and screws up the otherwise useful output. Normally, I've been selecting all of the columns except for that one. However, I'm starting to join with another table and have like 20 columns now.

有没有一种方法可以指定最大列宽或在a之后截断列一定数量的字符?

Is there a way to specify the maximum column width or to truncate a column after a certain number of characters?

我尝试了 \x 。有点帮助...但是在大多数情况下,一切仍然看起来很混乱。

I tried \x. It kind of helped... but for the most part everything still looks scrambled.

推荐答案

您可以通过<$指定列宽c $ c> \pset列X


postgres=# select 'some longer text some longer text some longer text some longer text some longer text some longer text';
┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                               ?column?                                                │
╞═══════════════════════════════════════════════════════════════════════════════════════════════════════╡
│ some longer text some longer text some longer text some longer text some longer text some longer text │
└───────────────────────────────────────────────────────────────────────────────────────────────────────┘
(1 row)

postgres=# \pset format wrapped 
Output format is wrapped.
postgres=# \pset columns 20
Target width is 20.
postgres=# select 'some longer text some longer text some longer text some longer text some longer text some longer text';
┌──────────────────┐
│     ?column?     │
╞══════════════════╡
│ some longer text…│
│… some longer tex…│
│…t some longer te…│
│…xt some longer t…│
│…ext some longer …│
│…text some longer…│
│… text            │
└──────────────────┘
(1 row)

请确保您的寻呼机配置正确-设置全局变量:

Be sure, so your pager is well configured - set global variables:


export PAGER=less
export LESS='-iMSx4 -RSFX -e'

这篇关于在psql中显示查询结果时,是否可以设置列的最大宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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