postgresql - JOOQ - 更新新添加的列
问题描述
我正在使用 JOOQ 和 Postgresql 数据库,我正在尝试将新列添加到表中,然后使用值更新这些列。这些值对应于推文的情绪。
到目前为止,我的尝试(没有编译错误的那个:)是:
final String SENTIMENT_NEGATIVE = "sentiment_negative";
final String SENTIMENT_NEUTRAL = "sentiment_neutral";
final String SENTIMENT_POSITIVE = "sentiment_positive";
final String SENTIMENT_COMPOUND = "sentiment_compound";
context.alterTable(Tweets.TWEETS).addColumnIfNotExists(SENTIMENT_NEGATIVE, DOUBLE).execute();
context.alterTable(Tweets.TWEETS).addColumnIfNotExists(SENTIMENT_NEUTRAL , DOUBLE).execute();
context.alterTable(Tweets.TWEETS).addColumnIfNotExists(SENTIMENT_POSITIVE, DOUBLE).execute();
context.alterTable(Tweets.TWEETS).addColumnIfNotExists(SENTIMENT_COMPOUND, DOUBLE).execute();
// example usage
for (Record record: tweetsResult) {
String tweet = record.get(Tweets.TWEETS.CONTENT);
SentimentAnalyzer sentimentAnalyzer = new SentimentAnalyzer(tweet);
sentimentAnalyzer.analyze();
log.debug(sentimentAnalyzer.getPolarity() + " | " + tweet);
context.update(Tweets.TWEETS)
.set(
row(SENTIMENT_NEGATIVE,
SENTIMENT_NEUTRAL,
SENTIMENT_POSITIVE,
SENTIMENT_COMPOUND),
row(getPolarity(sentimentAnalyzer, SENTIMENT_NEGATIVE),
getPolarity(sentimentAnalyzer, SENTIMENT_NEUTRAL),
getPolarity(sentimentAnalyzer, SENTIMENT_POSITIVE),
getPolarity(sentimentAnalyzer, SENTIMENT_COMPOUND))
)
.where(Tweets.TWEETS.ID.eq(record.get(Tweets.TWEETS.ID)))
.execute();
}
但我收到一个错误:
线程“主”org.jooq.exception.DataAccessException 中的异常:SQL [更新“公共”。“推文”设置(?,?,?,?)=行(?,?,?,?)其中“公共”。 "推文"."id" = ?]; 错误:“$1”处或附近的语法错误
我知道我可以根据 db 模式的变化重新生成我的源代码,但我想知道是否可以使用我的方法来做到这一点。
解决方案
推荐阅读
- c++ - 有什么方法可以返回主菜单吗?
- database - 对尝试感到困惑......除了在vb中
- javascript - 使用对象值动态合并数组
- python - 为什么 set() 构造函数比 list() 慢
- r - ggplot2 分组箱线图不会将不同时间点的组分开
- amazon-web-services - Redmine数据库yml中的AWS RDS SSL连接错误mysql2
- python - 这个模块'utils'的具体包是什么?
- haskell - 具有来自 IO 的第一个值的列表
- php - 我想从我的 php 表中提取值。我已在表格中嵌入表格,但无法使用 $_POST 获取值
- c - 运行 C 输出时拒绝访问