首页 \ 问答 \ MySQL触发器的IF条件(IF condition on MySQL trigger)

MySQL触发器的IF条件(IF condition on MySQL trigger)

我有两个表(表A,表B)具有相同的字段(user_id,domi,ipiresia)。 用户可以在表A中添加值。我希望只有当表B中没有包含user_id时,才会在表B中自动插入这些值。

CREATE TRIGGER new_value_added 
AFTER INSERT ON table_a
FOR EACH ROW
  IF NEW.user_id != user_id
  INSERT INTO table_b (user_id, domi, ipiresia)
  VALUES (NEW.user_id, NEW.domi, NEW.ipiresia);

我知道IF语句是错误的,因为触发器不能按预期工作。 有帮助吗?


I have two tables (Table A, Table B) with the same fields (user_id, domi, ipiresia). Users can add values in Table A. I want these values to be inserted automatically in Table B BUT only when the user_id is not included in Table B. on.

CREATE TRIGGER new_value_added 
AFTER INSERT ON table_a
FOR EACH ROW
  IF NEW.user_id != user_id
  INSERT INTO table_b (user_id, domi, ipiresia)
  VALUES (NEW.user_id, NEW.domi, NEW.ipiresia);

I know that the IF statement is wrong because the trigger doesn't work as expected. Any help?


原文:https://stackoverflow.com/questions/33007001
更新时间:2023-05-31 08:05

最满意答案

SHOW META ,它本身也显示了很多有用的信息......

SHOW PLAN - 如果想要诊断解析自身的全文查询 http://sphinxsearch.com/docs/current.html#sphinxql-show-plan

PACKEDFACTORS() - 函数可以告诉你更多关于如何计算排名的信息 http://sphinxsearch.com/docs/current.html#expr-func-packedfactors

SHOW PROFILE - 可以帮助解决性能问题http://sphinxsearch.com/docs/current.html#sphinxql-show-profile

并且DESCRIBE indexname通常对查看索引中的字段和属性非常有用http://sphinxsearch.com/docs/current.html#sphinxql-describe

最后, indextool --dumpheader对于检查特定索引的配置非常有用。 http://sphinxsearch.com/docs/current.html#ref-indextool (实际上它的其他命令也很有用!)


As well as SHOW META, which itself shows much useful info...

SHOW PLAN - if want to diagnose the full-text query parsing itself http://sphinxsearch.com/docs/current.html#sphinxql-show-plan

PACKEDFACTORS() - function can tell you more than you need to know about how ranking calculated http://sphinxsearch.com/docs/current.html#expr-func-packedfactors

SHOW PROFILE - can help with performance issues http://sphinxsearch.com/docs/current.html#sphinxql-show-profile

And DESCRIBE indexname is often useful to see exactly what Fields and Attributes in an index http://sphinxsearch.com/docs/current.html#sphinxql-describe

Finally indextool --dumpheader can be very useful to check the configuration for a specific index. http://sphinxsearch.com/docs/current.html#ref-indextool (actually its other commands can be useful too!)

相关问答

更多
  • Sphinx本身不支持WHERE子句中的“OR”。 但可以做类似的事情 SELECT id, (attribute_a = 'Value' OR attribute_b = 'Value') AS test FROM index WHERE test = 1 这有点令人费解,但确实有效。 也不知道你用什么库来构建查询,所以留下来作为如何构建如上所述的SQL查询的练习。 (另请注意,我改为调用列,而是改为属性.Sphinx对属性和字段的处理方式截然不同。澄清这是一种过滤属性的方法 ) Sphinx itse ...
  • 你的sql_joined_field不太正确,但你有正确的想法。 sql_query = select id, name from book sql_joined_field = category_names from query;\ select book.id, category.name \ from book join category on category.id = book.category_id \ ...
  • 我不确定是否有一种优雅的方式来做到这一点,我很害怕。 我能想到的唯一选择是在你的索引定义中这样: (2008..Date.today.year).each do |year| has "SUM(CASE WHEN YEAR(posts.created_at) = #{year} THEN rating ELSE 0 END", as: "total_rating_for_#{year}".to_sym, type: :float end I'm not sure if there's an e ...
  • 以下解决了我的问题! Product.search "\"#{search_text}\"/1" 最后的/1使它工作,它被称为Quorum运算符 。 The following resolved my problem! Product.search "\"#{search_text}\"/1" The /1 at the end makes it work, and it's called the Quorum operator.
  • 在OS X El Capitan上安装sphinx后,我遇到了类似的问题。 我使用pip install sphinx --user : pip install sphinx --user 。 尽管~/Library/Python/2.7/bin存在sphinx-build二进制文件,但找不到该命令。 问题是我的路径设置为PATH="~/Library/Python/2.7/bin:$PATH" 。 用$HOME替换波浪号~以便PATH="$HOME/Library/Python/2.7/bin:$PATH ...
  • Sphinx-doc生成的文件是静态的,因此您只需要静态发送。 在send_file文档之后,它将类似于: @app.route('/docs', defaults={'filename': 'index.html'}) @app.route('/docs/') def documentation(filename): return flask.send_from_directory( app.config['UPLOAD_FOLDER'], ...
  • 它的一个鲜为人知的功能,但配置文件可以成为一个脚本 - 如PHP,perl甚至普通的旧bash。 只需使用经典的shebang系列 - 如果第一行以#开头! intpreter用于执行脚本,输出用作conf文件。 PHP的示例.. #!/usr/bin/php searchd { pid_file = /searchd.pid } 作为旁注,为 ...
  • 和SHOW META ,它本身也显示了很多有用的信息...... SHOW PLAN - 如果想要诊断解析自身的全文查询 http://sphinxsearch.com/docs/current.html#sphinxql-show-plan PACKEDFACTORS() - 函数可以告诉你更多关于如何计算排名的信息 http://sphinxsearch.com/docs/current.html#expr-func-packedfactors SHOW PROFILE - 可以帮助解决性能问题http ...
  • 为项目添加所需的语法资源。 修复源代码中资源的路径。 如果您的类是com.mycompany.spechrecognizer ,则资源URL可能也是resource:/com/mycompany/spechrecognizer/ Add required grammar resources to your project. Fix path to the resources in source code. If your class is com.mycompany.spechrecognizer, the ...
  • 在文档MVA和sql_attr_multi中查看MVA - 多值属性。 我过去曾用这个来搜索“人”的“利益”。 所以我可能喜欢摇滚乐和看橄榄球。 Sphinx可以在数组中对此进行索引,您可以使用OR或AND匹配来搜索它们。 Take a look at MVA - Multi Value Attributes, in the documentation MVA and sql_attr_multi. I have used this in the past to search "interests" aga ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)