同像性和 SQL

发布于 2024-10-03 12:52:15 字数 1292 浏览 7 评论 0 原文

我目前正在使用 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;

您会看到我必须在 < 之间添加逗号code>visit_key 和 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 顺便说一句。

I'm currently using emacs sql-mode as my sql shell, a (simplified) query response is below:

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)

If I want to then formulate another query based on that data, e.g.

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

You'll see that I have to add the comma between visit_key and created, and surround the expiry value with quotes.

Is there a SQL DB shell that shows it's content more homoiconically, so that I could minimise this sort of editing? e.g.

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

or

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

I'm using postgresql btw.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_失温 2024-10-10 12:52:15

这是一个想法,与我有时所做的类似,尽管我不确定这是否正是您所要求的:

运行 Lisp 编译器(例如 SBCL) 在 SLIME 中。然后加载CLSQL。它有一个“功能数据操作语言”(SELECT 文档),可能会帮助您做一些事情如您所愿,也许可以与 SLIME 的自动完成功能结合使用。如果没有,定义 Lisp 函数和宏也很容易(假设您了解 Lisp,但您已经是 Emacser!)。

它没有提供开箱即用的大多数 SQL 接口所具有的格式良好的表,但即使这样添加也不是太难。 Lisp 确实足够强大,可以让人们轻松地想出一些方法来使您的常见操作变得更容易。

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.

衣神在巴黎 2024-10-10 12:52:15

我发现 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

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

I've found the following changes in psql go some way to giving me homoiconicity:

=# 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

caveats: everything is a string, and it's missing start and end quotes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文