增加雪花中现有的序列
我正在尝试增加使用雪花中序列生成的现有ID字段。
参考,这是代码&示例输出:
代码
CREATE OR REPLACE SEQUENCE id_sequence
START WITH 1
INCREMENT BY 1
;
输出
Id Keyword URL Type Position_Group
1 A A Ad 1
2 A B Ad 2
3 A C Organic 1
4 A D Organic 2
5 A E Organic 3
6 A F Featured_Snippet 1
尝试添加使用序列增加此表上的新数据尚未提供我需要的所需输出)。试图使用Alter序列并使用Max(ID)作为变量以传递为序列,但到目前为止没有运气。感谢任何建议!
所需的输出
Id Keyword URL Type Position_Group
1 A A Ad 1
2 A B Ad 2
3 A C Organic 1
4 A D Organic 2
5 A E Organic 3
6 A F Featured_Snippet 1
--
7 A G Organic 4
8 A H Organic 5
I'm trying to increment an existing ID field that was generated using sequence in snowflake.
For reference here's the code & sample output:
Code
CREATE OR REPLACE SEQUENCE id_sequence
START WITH 1
INCREMENT BY 1
;
Output
Id Keyword URL Type Position_Group
1 A A Ad 1
2 A B Ad 2
3 A C Organic 1
4 A D Organic 2
5 A E Organic 3
6 A F Featured_Snippet 1
Trying to add new data that increments on this table using sequence has not provided the desired output that I need which to increment based off of the max(Id). Tried to use ALTER SEQUENCE and use max(Id) as a variable to pass into sequence but no luck so far. Appreciate any recommendations!
Desired Output
Id Keyword URL Type Position_Group
1 A A Ad 1
2 A B Ad 2
3 A C Organic 1
4 A D Organic 2
5 A E Organic 3
6 A F Featured_Snippet 1
--
7 A G Organic 4
8 A H Organic 5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您正在尝试实现SCD,并且您希望替代密钥会增加1-每次插入新记录时 - 如果这是您想要的,那么我不建议您使用序列。
您应该使用“自动启动”概念。
创建或替换表Test_surogate_key(
test_id编号(38,0)未自动插入,
test_name varchar(2),
);
让我知道这是否有帮助。
I think you are trying to implement SCD and you want the surrogate keys to be incremented by 1 - each time a new record is inserted - if this is what you are looking for then I wouldn't recommend you to use sequence.
You should use "autoincrement" concept.
create or replace TABLE test_surrogate_key (
test_ID NUMBER(38,0) NOT NULL autoincrement,
test_name VARCHAR(2),
);
Let me know if this helps.
如果您反复运行第一行,这就是为什么您总是从1开始获得ID的原因。我认为您已经说出了一个问题。.
您创建表格,如果评论出来,
请访问:
秒2次运行给出:
因此,如果我们不重新创建序列以及如何使用序列以及它的工作原理。
我想我仍在努力理解您的挣扎是什么。
If you run that first line repeatedly, this is why you always get id starting at 1. Which I think you have said is a problem..
You CREATE table, if commented out to just be a SELECT
gives:
second run gives:
So if we don't recreate the sequence and how it's used it works how I would expect.
I guess I am still struggling to understand what your struggle is.