2

我目前正在使用 emacs sql-mode 作为我的 sql shell,一个(简化的)查询响应如下:

my_db=# select * from visit limit 4;

num |        visit_key            |          created           |    expiry
----+-----------------------------+----------------------------+------------
 1  | 0f6fb8603f4dfe026d88998d81a | 2008-03-02 15:17:56.899817 | 2008-03-02
 2  | 7c389163ff611155f97af692426 | 2008-02-14 12:46:11.02434  | 2008-02-14
 3  | 3ecba0cfb4e4e0fdd6a8be87b35 | 2008-02-14 16:33:34.797517 | 2008-02-14
 4  | 89285112ef2d753bd6f5e51056f | 2008-02-21 14:37:47.368657 | 2008-02-21
(4 rows)

如果我想根据该数据制定另一个查询,例如

my_db=# select visit_key, created from visit where expiry = '2008-03-02' 
           and num > 10;

您会看到我必须在visit_keyand之间添加逗号created,并用引号将到期值括起来。

是否有一个 SQL DB shell 可以更一致地显示其内容,以便我可以最大限度地减少这种编辑?例如

num, visit_key, created, expiry           
(1, '0f6fb8603f4dfe026d88998d81a', '2008-03-02 15:17:56.899817', '2008-03-02')

或者

(num=1, visit_key='0f6fb8603f4dfe026d88998d81a', 
    created='2008-03-02 15:17:56.899817', expiry='2008-03-02')      

我正在使用 postgresql 顺便说一句。

4

2 回答 2

1

Here's one idea, which is similar to what I do sometimes, though I'm not sure that it's exactly what you're asking for:

Run a Lisp compiler (like SBCL) in SLIME. Then load CLSQL. It has a "Functional Data Manipulation Language" (SELECT documentation) which might help you do something like you want, perhaps in conjunction with SLIME's autocompletion capabilities. If not, it's easy to define Lisp functions and macros (assuming you know Lisp, but you're already an Emacser!).

Out-of-the-box, it doesn't give the nicely formatted tables that most SQL interfaces have, but even that isn't too hard to add. And Lisp is certainly powerful enough to let one easily come up with ways to make your common operations easier.

于 2010-11-26T20:05:35.727 回答
0

我发现 psql 中的以下更改在某种程度上给了我同音性:

=# select remote_ip, referer, http_method, time from hit limit 1;
    remote_ip    | referer | http_method |           time            
-----------------+---------+-------------+---------------------------
 213.233.132.148 |         | GET         | 2013-08-27 08:01:42.38808
(1 row)
=# \a
Output format is unaligned.
=# \f ''', '''
Field separator is "', '".
=# \t
Showing only tuples.
=# select remote_ip, referer, http_method, time from hit limit 1;
213.233.132.148', '', 'GET', '2013-08-27 08:01:42.38808

警告:一切都是字符串,并且缺少开始和结束引号。

于 2013-10-03T10:33:34.660 回答