     }
     
     func singleValueContainer() throws -> SingleValueDecodingContainer {
-        // Asked for a value type: column name required
-        guard let codingKey = codingPath.last else {
-            throw DecodingError.typeMismatch(
-                RowDecoder.self,
-                DecodingError.Context(codingPath: codingPath, debugDescription: "single value decoding requires a coding key"))
-        }
-        return RowSingleValueDecodingContainer(row: row, codingPath: codingPath, column: codingKey)
+        throw DecodingError.typeMismatch(
+            RowDecoder.self,
+            DecodingError.Context(codingPath: codingPath, debugDescription: "single value decoding is not supported"))
+    }
+}
+
+private struct RowSingleValueDecoder: Decoder {
+    let row: Row
+    
+    init(row: Row, codingPath: [CodingKey]) {
+        assert(!codingPath.isEmpty, "coding key required")
+        self.row = row
+        self.codingPath = codingPath
+    }
+    
+    // Decoder
+    let codingPath: [CodingKey]
+    var userInfo: [CodingUserInfoKey : Any] { return [:] }
+    
+    func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
+        throw DecodingError.typeMismatch(
+            UnkeyedDecodingContainer.self,
+            DecodingError.Context(codingPath: codingPath, debugDescription: "keyed decoding is not supported"))
+    }
+    
+    func unkeyedContainer() throws -> UnkeyedDecodingContainer {
+        throw DecodingError.typeMismatch(
+            UnkeyedDecodingContainer.self,
+            DecodingError.Context(codingPath: codingPath, debugDescription: "unkeyed decoding is not supported"))
+    }
+    
+    func singleValueContainer() throws -> SingleValueDecodingContainer {
+        return RowSingleValueDecodingContainer(row: row, codingPath: codingPath, column: codingPath.last!)
     }
 }
 

        if let type = T.self as? DatabaseValueConvertible.Type {
            // Prefer DatabaseValueConvertible decoding over Decodable.
            // This allows decoding Date from String, or DatabaseValue from NULL.
            return type.decode(from: row[column.stringValue], conversionContext: ValueConversionContext(row).atColumn(column.stringValue)) as! T
        } else {
            return try T(from: RowDecoder(row: row, codingPath: [column]))
        }
    }
}

                return type.decode(from: row, atUncheckedIndex: index) as! T
            } else {
                do {
                    // This decoding will fail for types that decode from keyed
                    // or unkeyed containers, because we're decoding a single
                    // value here (string, int, double, data, null). If such an
                    // error happens, we'll switch to JSON decoding.
                    return try T(from: RowSingleValueDecoder(row: row, codingPath: codingPath + [key]))
                } catch let error as DecodingError {
                    if case .typeMismatch(_, let context) = error,
                        context.debugDescription == "keyed decoding is not supported" || context.debugDescription == "unkeyed decoding is not supported",
                        let data = row.dataNoCopy(atIndex: index)
                    {
                        return try JSONDecoder().decode(type.self, from: data)
                    } else {
                        throw error
                    }
                }
            }
