.. versionadded:: 2019.0.0

    Grant default privileges on a postgres object

    CLI Example:

    .. code-block:: bash

        salt '*' postgres.default_privileges_grant user_name table_name table \\
        SELECT,UPDATE maintenance_db=db_name

    name
       Name of the role to which default privileges should be granted

    object_name
       Name of the object on which the grant is to be performed

    object_type
       The object type, which can be one of the following:

       - table
       - sequence
       - schema
       - group
       - function

    privileges
       Comma separated list of privileges to grant, from the list below:

       - INSERT
       - CREATE
       - TRUNCATE
       - TRIGGER
       - SELECT
       - USAGE
       - UPDATE
       - EXECUTE
       - REFERENCES
       - DELETE
       - ALL

    grant_option
        If grant_option is set to True, the recipient of the default privilege can
        in turn grant it to others

    prepend
        Table and Sequence object types live under a schema so this should be
        provided if the object is not under the default `public` schema

    maintenance_db
        The database to connect to

    user
        database username if different from config or default

    password
        user password if any password for a specified user

    host
        Database host if different from config or default

    port
        Database port if different from config or default

    runas
        System user all operations should be performed on behalf of

def default_privileges_grant(name,
        object_name,
        object_type,
        defprivileges=None,
        grant_option=None,
        prepend='public',
        maintenance_db=None,
        user=None,
        host=None,
        port=None,
        password=None,
        runas=None):
    '''
    .. versionadded:: 2019.0.0

    Grant default privileges on a postgres object

    CLI Example:

    .. code-block:: bash

        salt '*' postgres.default_privileges_grant user_name table_name table \\
        SELECT,UPDATE maintenance_db=db_name

    name
       Name of the role to which default privileges should be granted

    object_name
       Name of the object on which the grant is to be performed

    object_type
       The object type, which can be one of the following:

       - table
       - sequence
       - schema
       - group
       - function

    privileges
       Comma separated list of privileges to grant, from the list below:

       - INSERT
       - CREATE
       - TRUNCATE
       - TRIGGER
       - SELECT
       - USAGE
       - UPDATE
       - EXECUTE
       - REFERENCES
       - DELETE
       - ALL

    grant_option
        If grant_option is set to True, the recipient of the default privilege can
        in turn grant it to others

    prepend
        Table and Sequence object types live under a schema so this should be
        provided if the object is not under the default `public` schema

    maintenance_db
        The database to connect to

    user
        database username if different from config or default

    password
        user password if any password for a specified user

    host
        Database host if different from config or default

    port
        Database port if different from config or default

    runas
        System user all operations should be performed on behalf of
    '''
    object_type, pdefrivileges, _defprivs = _mod_defpriv_opts(object_type, defprivileges)

    _validate_default_privileges(object_type, _defprivs, defprivileges)

    if has_default_privileges(name, object_name, object_type, defprivileges,
        prepend=prepend, maintenance_db=maintenance_db, user=user,
            host=host, port=port, password=password, runas=runas):
        log.info('The object: %s of type: %s already has default privileges: %s set',
            object_name, object_type, defprivileges)
        return False

    _grants = ','.join(_defprivs)

    if object_type in ['table', 'sequence']:
        on_part = '{0}."{1}"'.format(prepend, object_name)
    elif object_type == 'function':
        on_part = '{0}'.format(object_name)
    else:
        on_part = '"{0}"'.format(object_name)

    if grant_option:
        if object_type == 'group':
            query = ' ALTER DEFAULT PRIVILEGES GRANT {0} TO "{1}" WITH ADMIN OPTION'.format(
                object_name, name)
        elif (object_type in ('table', 'sequence', 'function') and
                object_name.upper() == 'ALL'):
            query = 'ALTER DEFAULT PRIVILEGES IN SCHEMA {2} GRANT {0} ON {1}S  TO ' \
                    '"{3}" WITH GRANT OPTION'.format(
                _grants, object_type.upper(), prepend, name)
        else:
            query = 'ALTER DEFAULT PRIVILEGES IN SCHEMA {2} GRANT {0} ON {1}S  TO "{3}" WITH GRANT OPTION'.format(
                _grants, object_type.upper(), on_part, name)
    else:
        if object_type == 'group':
            query = 'ALTER DEFAULT PRIVILEGES GRANT {0} TO "{1}"'.format(object_name, name)
        elif (object_type in ('table', 'sequence') and
                object_name.upper() == 'ALL'):
            query = 'ALTER DEFAULT PRIVILEGES IN SCHEMA {2} GRANT {0} ON  {1}S  TO "{3}"'.format(
                _grants, object_type.upper(), prepend, name)
        else:
            query = ' ALTER DEFAULT PRIVILEGES IN SCHEMA {2} GRANT {0} ON {1}S TO "{3}"'.format(
                _grants, object_type.upper(), prepend, name)

    ret = _psql_prepare_and_run(['-c', query],
                                user=user,
                                host=host,
                                port=port,
                                maintenance_db=maintenance_db,
                                password=password,
                                runas=runas)

    return ret['retcode'] == 0