MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / query

Function query

misc/python/materialize/cli/mz_workload_capture.py:46–78  ·  view source on GitHub ↗
(
    conn: psycopg.Connection,
    sql: LiteralString | bytes | SQL | Composed,
    timeout: int | None = None,
)

Source from the content-addressed store, hash-verified

44
45
46def query(
47 conn: psycopg.Connection,
48 sql: LiteralString | bytes | SQL | Composed,
49 timeout: int | None = None,
50) -> list[Any]:
51 if VERBOSE:
52 print(f"\n> {to_sql_string(sql, conn)}")
53
54 cancel_timer: threading.Timer | None = None
55
56 try:
57 if timeout is not None:
58 cancel_timer = threading.Timer(timeout, conn.cancel)
59 cancel_timer.start()
60
61 with conn.cursor() as cur:
62 cur.execute(sql)
63 return cur.fetchall()
64 except psycopg.errors.QueryCanceled:
65 if VERBOSE:
66 print("Too slow")
67 return []
68 except KeyboardInterrupt:
69 conn.cancel()
70 if VERBOSE:
71 raise
72 print(f"\n> {to_sql_string(sql, conn)}")
73 with conn.cursor() as cur:
74 cur.execute(sql)
75 return cur.fetchall()
76 finally:
77 if cancel_timer is not None:
78 cancel_timer.cancel()
79
80
81def attach_source_statistics(

Callers 2

attach_avg_column_sizesFunction · 0.70
mainFunction · 0.70

Calls 5

to_sql_stringFunction · 0.85
cursorMethod · 0.80
startMethod · 0.45
executeMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected