postgresql Postgres/Flyway:如何在sql文件中封装长常量字符串?

tf7tbtn2  于 2023-05-28  发布在  PostgreSQL
关注(0)|答案(2)|浏览(124)

我想在我的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并在字符串中输入,它会生成以下内容:

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

但是运行migrate操作会出现错误PSQLException: ERROR: syntax error at or near "||"
版本:Flyway 4.2,Postgres 10

r7knjye2

r7knjye21#

在SQL中将一个字符串拆分到各行是非常好的(没有任何串联运算符):

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

wtzytmuj2#

仅 Package 源代码而不是字符串内容的替代答案:

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

编辑
这显然被称为“隐式字符串连接”,Postgres文档说这是SQL标准的一部分:https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS
显然,它最初是一个C的东西:https://softwareengineering.stackexchange.com/a/255021
这是有意义的,实际上也是为什么我首先寻找这个功能。
80chars4life哟。

相关问题