MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / get_table_info

Function get_table_info

web/pgadmin/llm/tools/database.py:629–784  ·  view source on GitHub ↗

Get detailed information about a table including columns, constraints, and indexes. Uses pgAdmin's SQL templates for version-aware queries. Args: sid: Server ID did: Database ID schema_name: Schema name table_name: Table name Returns: D

(
    sid: int,
    did: int,
    schema_name: str,
    table_name: str
)

Source from the content-addressed store, hash-verified

627
628
629def get_table_info(
630 sid: int,
631 did: int,
632 schema_name: str,
633 table_name: str
634) -> dict:
635 """
636 Get detailed information about a table including columns,
637 constraints, and indexes.
638
639 Uses pgAdmin's SQL templates for version-aware queries.
640
641 Args:
642 sid: Server ID
643 did: Database ID
644 schema_name: Schema name
645 table_name: Table name
646
647 Returns:
648 Dictionary containing comprehensive table information
649 """
650 conn_id = f"llm_{secrets.choice(range(1, 9999999))}"
651 manager = None
652
653 try:
654 manager, conn = _get_connection(sid, did, conn_id)
655 status, error = _connect_readonly(manager, conn, conn_id)
656 if not status:
657 raise DatabaseToolError(f"Connection failed: {error}",
658 code="CONNECTION_ERROR")
659
660 sversion = manager.sversion or 0
661 driver = get_driver(config.PG_DEFAULT_DRIVER)
662
663 # Use qtLiteral for safe SQL escaping
664 schema_lit = driver.qtLiteral(schema_name, conn)
665 table_lit = driver.qtLiteral(table_name, conn)
666
667 # Get table OID first
668 oid_sql = f"""
669 SELECT c.oid, n.oid as schema_oid
670 FROM pg_catalog.pg_class c
671 JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
672 WHERE c.relname = {table_lit}
673 AND n.nspname = {schema_lit}
674 """
675
676 status, _ = conn.execute_void("BEGIN TRANSACTION READ ONLY")
677 if not status:
678 raise DatabaseToolError("Failed to start transaction",
679 code="TRANSACTION_ERROR")
680
681 try:
682 status, oid_res = conn.execute_dict(oid_sql)
683 if not status or not oid_res.get('rows'):
684 raise DatabaseToolError(
685 f"Table {schema_name}.{table_name} not found",
686 code="NOT_FOUND"

Callers 1

execute_toolFunction · 0.85

Calls 12

get_driverFunction · 0.90
compile_template_pathFunction · 0.90
_connect_readonlyFunction · 0.85
DatabaseToolErrorClass · 0.85
qtLiteralMethod · 0.80
joinMethod · 0.80
appendMethod · 0.80
_get_connectionFunction · 0.70
execute_voidMethod · 0.45
execute_dictMethod · 0.45
getMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected