Hi, I’m just getting started with streamlit in snowflake. I want user to select start_date and end_date and then excecute an sql query using these dates. I’m trying with st.date_input() and then querying with session.sql but I get the error ‘Date start_date is not recognized’.
Hi @Liina, welcome to the forum!
Here’s the pattern I like to use for something like this:
start_date, end_date = st.date_input(...)
# NOTE That the above code will actually raise an error if you only select
# a single date, even if you haven't gotten to selecting the second date yet
# If you want to avoid this, you can use this https://arnaudmiribel.github.io/streamlit-extras/extras/mandatory_date_range/ from streamlit-extras
# or just copy the code from that page (click `view source`)
session = st.connection("snowflake").session()
df = session.sql(
"select * from db.schema.table where date between ? and ?",
params=[start_date, end_date]
).to_pandas()
st.write(df)
# If this query is slow, you can also put it in a function, and use st.cache_data
# on the function so that if you rerun the page it's faster to get the
# query results