我应该在使用字符串替换进行更新时添加WHERE子句(Should I add a WHERE clause when updating with string replacements)
我想在整个列上执行字符串替换,将一个短语的所有实例更改为另一个:
UPDATE `some_records` SET `some_column` = REPLACE(`some_column`, 'foo', 'bar');
由于许多行不包含字符串'foo',因此它们不受此查询的影响,这很好; 我只关心包含它的行。 我的问题是,有没有理由添加一个WHERE子句来明确地定位将受影响的行? 例如
UPDATE `some_records` SET `some_column` = REPLACE(`some_column`, 'foo', 'bar') WHERE `some_column` LIKE '%foo%';
据我所知,两个查询都有完全相同的效果。 第二版有什么优势吗? 它是否提供更好的性能或任何其他好处? 到目前为止,我还没有找到文件说一个比另一个好。
I want to perform a string replacement on an entire column, changing all instances of one phrase to another:
UPDATE `some_records` SET `some_column` = REPLACE(`some_column`, 'foo', 'bar');
Since many of the rows do not contain the string 'foo' they will be unaffected by this query, which is fine; I only care about the rows that do contain it. My question is, is there any reason to add a WHERE clause to explicitly target the rows that will be affected? e.g.
UPDATE `some_records` SET `some_column` = REPLACE(`some_column`, 'foo', 'bar') WHERE `some_column` LIKE '%foo%';
As far as I can tell, both queries have the exact same effect. Is there any advantage to the 2nd version? Does it provide better performance or any other benefits? So far I haven't found documentation to say one is better than the other.
原文:https://stackoverflow.com/questions/31666490
最满意答案
Around表示执行建议而不是函数。 您仍然可以使用
ad-do-it
调用原始文件。 见信息只是添加一个小例子:
(defun foo (x) (* 2 x)) (defadvice foo (around bar activate) (setq ad-return-value (if (= x 1) 42 (+ 1 ad-do-it)))) (foo 1) ;; 42 (foo 2) ;; 5 (foo 3) ;; 7
Around means that the advice is executed instead of the function. You can still call the original with
ad-do-it
. See infoJust to add a small example:
(defun foo (x) (* 2 x)) (defadvice foo (around bar activate) (setq ad-return-value (if (= x 1) 42 (+ 1 ad-do-it)))) (foo 1) ;; 42 (foo 2) ;; 5 (foo 3) ;; 7
相关问答
更多-
如何调试elisp?(How to debug elisp?)[2021-08-04]
调试器(edebug)非常简单的使用。 转到功能的定义,并键入Mx edebug-defun 。 下次调用它时,您将能够像其他调试器一样遍历代码。 类型? 关于键盘列表,或查看edebug的文档。 The debugger (edebug) is pretty straight forward to use. Go to the definition of the function, and type M-x edebug-defun. The next time it is called, you'll ... -
期间是cons运算符,而不是lisp意义上的符号。 例如: (setq nums '(1 . 2)) 这相当于: (setq nums (cons 1 2)) The period is the cons operator and not a symbol in the lisp sense. E.g.: (setq nums '(1 . 2)) This is equivalent to: (setq nums (cons 1 2))
-
SQLite和elisp?(SQLite and elisp? [closed])[2022-01-26]
从Trey Jackson的起始链接看来,似乎有一篇关于如何为elisp 构建 一个低级进程sqlite的程序接口的教程,例如sqlite-query。 它基于屏幕抓取一个comint缓冲区只是为了这个目的(例如不重复使用sql.el)。 以下是从该参考复制的不完整示例。 ;; this is emacs lisp code (defun sqlite-query ( sql-command ) (set-buffer sqlite-output-buffer) ;1 (era ... -
使用elisp实现流(Implementing streams with elisp)[2022-09-04]
感谢@ Gerstmann的建议,我能够写出我正在寻找的建筑。 新的实现现在看起来像: (setq the-empty-stream nil) (defun stream-null? (s) (eq s the-empty-stream)) (defun my/sicp-delay (exp) `(lambda () ,exp)) (defun my/sicp-force (exp) (funcall exp)) (defmacro my/cons-stream (a b) (list 'cons a ( ... -
我的emacs给出了另一个错误: *** Eval error *** Wrong number of arguments: apply, 1 我认为它解释了一切。 My emacs gives another error: *** Eval error *** Wrong number of arguments: apply, 1 I think it explains everything.
-
Around表示执行建议而不是函数。 您仍然可以使用ad-do-it调用原始文件。 见信息 只是添加一个小例子: (defun foo (x) (* 2 x)) (defadvice foo (around bar activate) (setq ad-return-value (if (= x 1) 42 (+ 1 ad-do-it)))) (foo 1) ;; 42 (foo 2) ;; 5 (foo 3) ;; 7 Around ...
-
如何捕获需要用户交互的所有elisp函数调用?(How to catch all elisp function calls that require user interaction?)[2022-05-01]
我认为您可以使用“commandp”来判断特定功能是否是交互式的。 所以只需运行(remove-if 'commandp kill-buffer-query-functions) I just stumbled upon a possible answer to this: M-x describe-function minibuffer-with-setup-hook (minibuffer-with-setup-hook FUN &rest BODY) Add FUN to `minibuffer-se ... -
重复的问题(忽略另一个的'Windows'部分)。 我可以从Emacs向Windows发送按键吗? 您可以做的最好(如您所述)有不同的快捷方式。 例如,它们可以通过大写来区分 (global-set-key (kbd "C-x C-D") 'dired-with-some-switches) (global-set-key (kbd "C-x C-d") 'dired-with-other-switches) Duplicate question (ignoring the 'Windows' part ...
-
我建议不要使用建议,因为你可以在js-mode-map重新绑定Ck 。 例如 (defun my-kill-line-or-block (&optional arg) "Kill line or whole block if line ends with a block opener." (interactive "P") (if (looking-at ".*\\({[^{}\n]*$\\)") (kill-region (point) (pr ...
-
如何在瞬态标记模式下使elisp中的区域瞬态(How to make region transient in elisp when in transient-mark-mode)[2021-12-28]
问题是在运行使用此宏建议的命令后,该区域会失去其瞬态特性; 后续的移动命令扩展了区域,而不是取消选择它。 您应该更多地谈论“移位选择性质”:扩展区域的移动命令是以“正常”方式激活标记时发生的操作。 shift-select状态存储在transient-mark-mode变量中,并由不关心deactivate-mark值的某人( handle-shift-selection ?)修改。 我们可以通过保存transient-mark-mode的值来解决这个问题: (defmacro keep-region (c ...