             return
 
         push_param = (param, type) ->
-            if type.toUpperCase() == 'JSONB' and misc.is_array(param)
+            if type?.toUpperCase() == 'JSONB'
                 param = misc.to_json(param)  # I don't understand why this is needed by the driver....
             opts.params.push(param)
             return opts.params.length
 
+        if opts.jsonb_merge?
+            if opts.jsonb_set?
+                opts.cb("if jsonb_merge is set then jsonb_set must not be set")
+                return
+            opts.jsonb_set = opts.jsonb_merge
+
         if opts.jsonb_set?
-            opts.query += " SET "
-            v = []
-            for field, data of opts.jsonb_set
-                obj = "COALESCE(#{field}, '{}'::JSONB)"
+            # This little piece of very hard to write (and clever?) code
+            # makes it so we can set or **merge in at any nested level (!)
+            # arbitrary JSON objects.  We can also delete any key at any
+            # level by making the value null or undefined!  This is amazingly
+            # easy to use in queries -- basically making JSONP with postgres
+            # as expressive as RethinkDB REQL (even better in some ways).
+            set = (field, data, path) =>
+                obj = "COALESCE(#{field}#>'{#{path.join(',')}}', '{}'::JSONB)"
                 for key, val of data
                     if not val?
                         # remove key from object
                         obj = "(#{obj} - '#{key}')"
                     else
-                        # add key to object
-                        obj = "JSONB_SET(#{obj}, '{#{key}}', $#{push_param(val, 'JSONB')}::JSONB)"
-                v.push(" #{field} = #{obj}")
-            opts.query += v.join(' , ')
+                        if opts.jsonb_merge? and typeof(val) == 'object'
+                            subobj = set(field, val, path.concat([key]))
+                            obj    = "JSONB_SET(#{obj}, '{#{key}}', #{subobj})"
+                        else
+                            # completely replace field[key] with val.
+                            obj = "JSONB_SET(#{obj}, '{#{key}}', $#{push_param(val, 'JSONB')}::JSONB)"
+                return obj
+            v = ("#{field}=#{set(field, data, [])}" for field, data of opts.jsonb_set)
+            opts.query += " SET " + v.join(' , ')
 
         if opts.values?
             if opts.where?

        throw Error("NotImplementedError")

    add_user_to_project: (opts) =>
        throw Error("NotImplementedError")

    remove_collaborator_from_project: (opts) =>
        throw Error("NotImplementedError")

        throw Error("NotImplementedError")

    create_project: (opts) =>
        opts = defaults opts,
            account_id  : required    # initial owner
            title       : undefined
            description : undefined
            cb          : required    # cb(err, project_id)
        if not @_validate_opts(opts) then return
        project_id = misc.uuid()
        now = new Date()
        @_query
            query  : "INSERT INTO projects"
            values :
                project_id  : project_id
                title       : opts.title
                description : opts.description
                created     : now
                last_edited : now
                users       : {"#{opts.account_id}":{group:'owner'}}
            cb : (err, result) =>
                opts.cb(err, if not err then project_id)

    get_project: (opts) =>
        throw Error("NotImplementedError")
