duanhe6799 2016-09-08 10:24
浏览 49
已采纳

通过迁移创建存储过程

I've a project in GO that check if there are new migrations to apply when the app starts (I'm using library https://github.com/mattes/migrate).

Now the problem is that I have a stored procedure to create in one of this migration (because this will be called later, and I need to create it in a migration otherwise the test suite will fail of course).

An example can be this one:

DELIMITER @@
    CREATE PROCEDURE get_value(my_id BIGINT(20), OUT out_value DOUBLE)
       BEGIN
         SELECT CASE
            WHEN o.financial_status = "test" THEN 0
            ELSE 1
            END
            INTO out_value
          FROM `order` o
          LEFT JOIN `my_table_2` io ON io.field_2 = o.id
          LEFT JOIN `my_table_3` ip ON io.field_3 = ip.id
          WHERE o.id = my_id;
END @@
DELIMITER ;

As far as I read, this might not be possible because sql driver for go does not support multi statement (we're using mysql 5.6).

There are any other way to do that? Thanks!

  • 写回答

1条回答 默认 最新

  • douhutongvm382381 2016-09-08 22:50
    关注

    I ran into the same situation, actually. The way I ran it is I removed all delimiter declarations and ran it. Since you don't need a delimiter within the migration, it will auto terminate (or realistically denominate) and the migration should run.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog