首页 \ 问答 \ 我应该在使用字符串替换进行更新时添加WHERE子句(Should I add a WHERE clause when updating with string replacements)

我应该在使用字符串替换进行更新时添加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
更新时间:2023-04-03 14:04

最满意答案

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 info

Just 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

相关问答

更多
  • 调试器(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))
  • 从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 ...
  • 感谢@ 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 ...
  • 我认为您可以使用“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 ...
  • 问题是在运行使用此宏建议的命令后,该区域会失去其瞬态特性; 后续的移动命令扩展了区域,而不是取消选择它。 您应该更多地谈论“移位选择性质”:扩展区域的移动命令是以“正常”方式激活标记时发生的操作。 shift-select状态存储在transient-mark-mode变量中,并由不关心deactivate-mark值的某人( handle-shift-selection ?)修改。 我们可以通过保存transient-mark-mode的值来解决这个问题: (defmacro keep-region (c ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。