sql - Scala Doobie 查询硬编码值
问题描述
在 Doobie 中编写以下查询时:
(SELECT id FROM (VALUES(?),(?),(?)) table(id))
UNION
SELECT id FROM table
我有数据列表,例如 List(1,2,3,4) ,它是可变大小的。如何使用 Doobie 将值列表插入 SQL VALUES CLAUSE?
解决方案
您好,您可以参考以下来自 doobie 官方社区页面的参考资料:
Consider a below table DDL:
CREATE TABLE country (
code character(3) NOT NULL,
name text NOT NULL,
population integer NOT NULL,
gnp numeric(10,2)
-- more columns, but we won't use them here
)
SQL 使用 doobie 语法,其中代码是不同大小的列表:
sql"""
select code, name, population, gnp
from country
where code in (${codes : codes.type})
""".query[Country]
推荐阅读
- python - Python:是否可以从另一个线程开始和停止 while 循环?
- environment-variables - 网站在 Windows 和 Linux 上运行。但它不适用于云
- html - 为什么我不能在 css 中更改类级别的 html 按钮的宽度?
- php - 使用 PHP 将 HTML 代码添加到现有的 HTML 文件
- python - 'list_display[2]' 的值指的是 'first_name',它不是可调用的、'UserAdmin' 的属性或 'authentication.User' 上的属性
- angular - 导航结束时隐藏 Ionic loader 问题
- winapi - 如何在 Windows 上查找所有字体路径
- swift - 适用于 iOS 的 MoPub:“目标未运行或缺少所需的目标权利”
- laravel-nova - BelongsToMany:nova 在 2 字模型“LongFeature”之间添加连字符
- perl - 带括号和不带括号的eof的区别?(Perl5)