from typing import Union
from typing import List


def table_insert(name: str, field_names: Union[str, List[str]]) -> str:
    """Return command to add a record into a PostgreSQL database.


    :param str name: name of table to append
    :param field_names: names of fields
    :type: str or list
    :return: command to append records to a table
    :rtype: str

    Example:

    import psql

    cur = psql.connection('db', 'user', 'password')
    [cur.execute(psql.table_insert('table', 'field'), (x, )) for x in values]
    """
    if isinstance(field_names, str):
        field_names = [field_names]

    length = len(field_names)
    if length > 1:
        values = ','.join(['%s'] * length)
    else:
        values = '%s'

    return '''INSERT INTO {table_name} ({fields})
              VALUES ({values});'''.format(table_name=name,
                                           fields=', '.join(field_names),
                                           values=values)