代码之家  ›  专栏  ›  技术社区  ›  Shorn

postgres/flyway:如何在SQL文件中包装长常量字符串?

  •  0
  • Shorn  · 技术社区  · 6 年前

    我想在我的Flyway迁移文件中对SQL进行换行,工作版本如下:

    comment on table account is
    'Multiple users may be associated with the same account (think multiple login methods, like gmail + facebook, etc.) ';
    

    如果我在字符串中使用IDEA并点击Enter,它将生成:

    comment on table account is
    'Multiple users may be associated with the same account (think multiple' ||
    ' login methods, like gmail + facebook, etc.) ';
    

    但是运行迁移操作会产生错误 PSQLException: ERROR: syntax error at or near "||" .

    版本:Flyway 4.2,Postgres 10

    2 回复  |  直到 6 年前
        1
  •  1
  •   a_horse_with_no_name    6 年前

    在SQL中跨行拆分字符串(不使用任何连接运算符)是非常好的:

    comment on table account is
    'Multiple users may be associated with the 
    same account (think multiple login methods, 
    like gmail + facebook, etc.)';
    
        2
  •  0
  •   Shorn    6 年前

    仅包装源代码而不是字符串内容的可选答案:

    comment on table account is
    'Multiple users may be associated with the same account (think multiple'
    ' login methods, like gmail + facebook, etc.)';