def foreign_key(
    table_name: str, schema: str, parent_name: str, parent_schema: str
) -> str:
    """Return column names (child and parent) of the foreign key."""

    return f"""
    SELECT
        att2.attname as child_column,
        att.attname as parent_column
    FROM
       (SELECT
            unnest(con1.conkey) AS parent,
            unnest(con1.confkey) AS child,
            con1.confrelid,
            con1.conrelid,
            con1.conname,
            ns2.nspname
        FROM
            pg_class cl
            JOIN pg_namespace ns ON cl.relnamespace = ns.oid
            JOIN pg_constraint con1 ON con1.conrelid = cl.oid
            JOIN pg_class cl2 on cl2.oid = con1.confrelid
            JOIN pg_namespace ns2 on ns2.oid = cl2.relnamespace
        WHERE
            cl.relname = '{table_name}' AND
            ns.nspname = '{schema}' AND
            cl2.relname = '{parent_name}' AND
            ns2.nspname = '{parent_schema}' AND
            con1.contype = 'f'
       ) con
       JOIN pg_attribute att ON
            att.attrelid = con.confrelid AND att.attnum = con.child
       JOIN pg_class cl ON
           cl.oid = con.confrelid
       JOIN pg_attribute att2 ON
           att2.attrelid = con.conrelid AND att2.attnum = con.parent
    """