from typing import Dict
from typing import List


def get_pg_table_columns(conn) -> Dict[str, List[str]]:
    """
    Returns a dictionary mapping table names to the list of their columns in ordinal order.
    Args:
        conn: The pg database connection.

    Returns: The dictionary of tables mapped to a list of their ordinal-orderd column names.
    """
    cursor = conn.cursor()
    cursor.execute("""
    SELECT cols.table_name, cols.column_name
      FROM information_schema.columns cols
      WHERE cols.column_name IS NOT NULL
      AND cols.table_name IS NOT NULL
      AND cols.table_name IN (
        SELECT tables.tablename FROM pg_catalog.pg_tables tables
        WHERE LOWER(schemaname) = 'public'
      )
    ORDER by cols.table_name, cols.ordinal_position;
    """)
    mapping = {}
    for row in cursor:
        mapping.setdefault(row[0], []).append(row[1])

    cursor.close()
    return mapping