主键约束,table 从本地数据库迁移到雪花,json 列的推荐数据类型?
Primary Key Constraint, migration of table from local db to snowflake, recommended data types for json column?
我可以按什么顺序将数据复制到两个不同的 table 中以符合我在本地创建的 table 约束?
我根据文档创建了一个示例,但希望获得有关如何通过选择正确类型来优化存储数据的建议。
我创建了两个 table,一个是姓名列表,第二个是姓名列表以及他们做某事的日期。
create or replace table name_key (
id integer not null,
id_sub integer not null,
constraint pkey_1 primary key (id, id_sub) not enforced,
name varchar
);
create or replace table recipts (
col_a integer not null,
col_b integer not null,
constraint fkey_1 foreign key (col_a, col_b) references name_key (id, id_sub) not enforced,
recipt_date datetime,
did_stuff variant
);
Insert into name_key values (0, 0, 'Geinie'), (1, 1, 'Greg'), (2,2, 'Alex'), (3,3, 'Willow');
Insert into recipts values(0,0, Current_date()), (1,1, Current_date()), (2,2, Current_date()), (3,3, Current_date());
Select * from name_key;
Select * from recipts;
Select * from name_key
join recipts on name_key.id = recipts.col_a
where id = 0 or col_b = 2;
我读到:https://docs.snowflake.net/manuals/user-guide/table-considerations.html#storing-semi-structured-data-in-a-variant-column-vs-flattening-the-nested-structure 其中建议将时间戳从字符串更改为变体。我没有包括第四列,我将其留空以备将来使用。本质上它以 json 格式捕获数据,因此我将其作为一个变体。重新考虑这个 table 结构来扁平化变体列会更好吗?
我也想把key改成AUTO_INCRDEMENT,Snowflake有这样的吗?
What order can I copy data into two different tables to comply with the table constraints I created locally?
您需要提供更多有关约束的上下文,但您可以控制复制语句的顺序。对于外键,通常您希望加载在执行引用的 table 之前引用的 table。
where it recommends to change timestamps from strings to a variant.
我认为您误读了该文档。它建议将变量列中的值提取到它们自己的单独列中(在本例中为时间戳列),特别是如果这些列是日期和时间、数组和字符串中的数字。
将时间戳列转换为变体,这正是它所建议的。
Would it be better to rethink this table structure to flatten the variant column?
在使用半结构化数据的情况下仔细考虑并进行性能测试肯定是好的,但没有关于您的具体情况和数据的更多信息,很难说。
Also I would like to change the key to AUTO_INCRDEMENT, is there something like this in Snowflake?
是的,雪花有 Auto_increment feature. Although I've heard this has some issue with working with COPY INTO Statements
我可以按什么顺序将数据复制到两个不同的 table 中以符合我在本地创建的 table 约束?
我根据文档创建了一个示例,但希望获得有关如何通过选择正确类型来优化存储数据的建议。
我创建了两个 table,一个是姓名列表,第二个是姓名列表以及他们做某事的日期。
create or replace table name_key (
id integer not null,
id_sub integer not null,
constraint pkey_1 primary key (id, id_sub) not enforced,
name varchar
);
create or replace table recipts (
col_a integer not null,
col_b integer not null,
constraint fkey_1 foreign key (col_a, col_b) references name_key (id, id_sub) not enforced,
recipt_date datetime,
did_stuff variant
);
Insert into name_key values (0, 0, 'Geinie'), (1, 1, 'Greg'), (2,2, 'Alex'), (3,3, 'Willow');
Insert into recipts values(0,0, Current_date()), (1,1, Current_date()), (2,2, Current_date()), (3,3, Current_date());
Select * from name_key;
Select * from recipts;
Select * from name_key
join recipts on name_key.id = recipts.col_a
where id = 0 or col_b = 2;
我读到:https://docs.snowflake.net/manuals/user-guide/table-considerations.html#storing-semi-structured-data-in-a-variant-column-vs-flattening-the-nested-structure 其中建议将时间戳从字符串更改为变体。我没有包括第四列,我将其留空以备将来使用。本质上它以 json 格式捕获数据,因此我将其作为一个变体。重新考虑这个 table 结构来扁平化变体列会更好吗?
我也想把key改成AUTO_INCRDEMENT,Snowflake有这样的吗?
What order can I copy data into two different tables to comply with the table constraints I created locally?
您需要提供更多有关约束的上下文,但您可以控制复制语句的顺序。对于外键,通常您希望加载在执行引用的 table 之前引用的 table。
where it recommends to change timestamps from strings to a variant.
我认为您误读了该文档。它建议将变量列中的值提取到它们自己的单独列中(在本例中为时间戳列),特别是如果这些列是日期和时间、数组和字符串中的数字。
将时间戳列转换为变体,这正是它所建议的。
Would it be better to rethink this table structure to flatten the variant column?
在使用半结构化数据的情况下仔细考虑并进行性能测试肯定是好的,但没有关于您的具体情况和数据的更多信息,很难说。
Also I would like to change the key to AUTO_INCRDEMENT, is there something like this in Snowflake?
是的,雪花有 Auto_increment feature. Although I've heard this has some issue with working with COPY INTO Statements