使用返回'雪花中的条款?
有没有简单的方法可以在雪花中执行“返回”条款?
例如,在Postgres中,我可以做类似
Col 1 | Col 2 |
---|---|
1 | XCVS |
2 | FDA |
INSERT INTO EXAMPLE_TABLE(COL_2)
VALUES('ABCD')
RETURNING COL_1
的事情,其中Col_1设置为自动增量ID,因此,对于上述查询,我希望结果“ 3”,并且表格为这样的
Col 1 | Col 2 |
---|---|
1 | XCVS |
2 | FDAS |
3 | ABCD |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
雪花似乎缺乏
返回
或last_insert_id
。一种选择是放弃自动启动初级键并使用显式。
然后,如果需要知道ID,您可以将其分配给变量并将其传递。这是how Rails does it.
或使用CTE。
如果不这样做,请让默认情况发生。
使用序列的优点,vs
从example_table
中选择Max(ID)+1,ISNextVal
将始终返回新的唯一ID。即使您同时执行了很多插入,也没有使用重复ID的危险,也不需要锁和交易。Snowflake seems to lack
returning
orlast_insert_id
.One option is to forego auto-incrementing primary keys and use a explicit sequence.
Then, if need to know the ID, you can assign it to a variable and pass it in. This is how Rails does it.
Or using a CTE.
And if you don't, let the default happen.
The advantage of using a sequence, vs
select max(id)+1 from example_table
, isnextval
will always return a new unique ID. Even if you're doing a lot of inserts at the same time, there's no danger of using a duplicate ID, and no need for locks nor transactions.