我在雪花大学做 Badge 3 并遇到错误。 ESS-DABW 徽章 3:数据应用程序构建器研讨会:第 5 课:待处理订单应用程序改进 🥋 完善 ORDERS 表定义。
下面是我在 Smoothies 数据库公共架构和订单表中的代码。
alter table SMOOTHIES.PUBLIC.ORDERS
add column order_uid integer --adds the column
default smoothies.public.order_seq.nextval --sets the value of the column to sequence
constraint order_uid unique enforced; --makes sure there is always a unique value in the column
create or replace table smoothies.public.orders (
order_uid integer default smoothies.public.order_seq.nextval,
order_filled boolean default false,
name_on_order varchar(100),
ingredients varchar(200),
constraint order_uid unique (order_uid),
order_ts timestamp_ltz default current_timestamp()
);
插入不起作用的语句:
insert into smoothies.public.orders
values ('Guava Cantaloupe Elderberries ', 'Abhi');
错误信息
插入值列表与期望 5 但得到 2 的列列表不匹配
我的 Streamlit 代码:
# Import python packages
import streamlit as st
from snowflake.snowpark.functions import col
from snowflake.snowpark.context import get_active_session
# Write directly to the app
st.title(":cup_with_straw: Customize Your Smoothie! :cup_with_straw:")
st.write(
"""Choose the fruits you want in your custom Smoothie!
"""
)
name_on_order= st.text_input('Name on Smoothie')
st.write('The name on your Smoothie will be:', name_on_order)
session= get_active_session()
my_dataframe = session.table("smoothies.public.fruit_options").select(col('Fruit_name'))
#st.dataframe(data=my_dataframe, use_container_width=True)
ingredients_list = st.multiselect('Choose up to 5 ingredients:', my_dataframe
)
if ingredients_list:
#st.write(ingredients_list)
#st.text(ingredients_list)
ingredients_string= ''
for fruit_chosen in ingredients_list:
ingredients_string+=fruit_chosen + ' '
#st.write(ingredients_string)
my_insert_stmt = """ insert into smoothies.public.orders
values ('""" + ingredients_string + """','""" + name_on_order+ """')"""
#st.write(my_insert_stmt)
#st.stop()
time_to_insert= st.button('Submit Order')
if time_to_insert:
session.sql(my_insert_stmt).collect()
st.success('Your Smoothie is ordered!', icon="✅")
如果您不提供明确的列列表,则这些值将与所有列匹配,正如错误所示 - 您有五列,但只有两个值。
假设您打算保留包含默认值的列,则可以显式列出没有默认值的列:
insert into smoothies.public.orders
(name_on_order, ingredients) -- Here
values ('Guava Cantaloupe Elderberries ', 'Abhi');