<@ULVA73B9P> how do I query the prefect database f...
# ask-marvin
e
@Marvin how do I query the prefect database for specific flow runs?
m
To query the Prefect database for specific flow runs, you'll need to interact with the database directly using SQL queries or use the Prefect API. However, since you're looking for the database approach, here's a code example that shows how you might query using the
snowflake_multiquery
function within a Prefect flow if you're using Snowflake as your database:
Copy code
python
from prefect import flow
from prefect_snowflake.credentials import SnowflakeCredentials
from prefect_snowflake.database import SnowflakeConnector, snowflake_multiquery

@flow
def snowflake_multiquery_flow():
    snowflake_credentials = SnowflakeCredentials(
        account="account",
        user="user",
        password="password",
    )
    snowflake_connector = SnowflakeConnector(
        database="database",
        warehouse="warehouse",
        schema="schema",
        credentials=snowflake_credentials
    )
    result = snowflake_multiquery(
        ["SELECT * FROM table WHERE id=%{id_param}s LIMIT 8;", "SELECT 1,2"],
        snowflake_connector,
        params={"id_param": 1},
        as_transaction=True
    )
    return result

snowflake_multiquery_flow()
You can adjust the example to fit the specifics of your database and what information you are querying for. Please replace
"account"
,
"user"
,
"password"
,
"database"
,
"warehouse"
,
"schema"
, and the SQL query as per your needs. The example is specific to Snowflake, so if you're using a different database, you'll need to construct a similar query using the relevant library or connector for that database. You can read more about using Snowflake with Prefect in the documentation. And if you are interested in understanding how flow runs are deployed and executed within Prefect, you might want to visit the Prefect blocks and deployments documentation.
n
🧐
nope there's a
read_flow_runs
client method that accepts a flow_run_filter
e
Thanks Nate!
Overthrow the robots
🔨 1