diff --git a/postmodern/table.lisp b/postmodern/table.lisp
index 23fc8d8..fea1c4e 100644
--- a/postmodern/table.lisp
+++ b/postmodern/table.lisp
@@ -227,6 +227,12 @@ (defun build-dao-methods (class)
                     :for field :in unbound
                     :do (setf (slot-value object field) value)))))
            object)
+         (defmethod sql-escape ((arg ,class))
+           (let ((keys (dao-keys (class-of arg))))
+             (if (= 1 (length keys))
+                 (sql-escape (slot-value arg (car keys)))
+                 (error "Class ~A doesn't have exactly one key, and therefore instances can't be converted to an SQL literal."
+                        (class-of arg)))))
 
 
          (let* ((defaulted-slots (remove-if-not (lambda (x) (slot-boundp x 'col-default))
@@ -332,6 +338,25 @@ (defmacro select-dao (type &optional (test t) &rest ordering)
       `(let ((,type-name ,type))
          (query-dao% ,type-name (sql ,query))))))
 
+(defun column-slot (class slot-name)
+  (find slot-name (dao-column-slots class) :key #'slot-definition-name))
+
+(defgeneric actual-col-type (type)
+  (:method ((type cons))
+    (cons (car type)
+          (mapcar #'actual-col-type (cdr type))))
+  (:method ((type symbol))
+    (let ((class (find-class type nil)))
+      (if (and class
+               (typep class 'dao-class)
+               (= 1 (length (dao-keys class))))
+          (let ((real-type (column-type (column-slot class
+                                                     (car (dao-keys class))))))
+            (if (string= real-type 'serial)
+                'int
+                (actual-col-type real-type)))
+          type))))
+
 (defun dao-table-definition (table)
   "Generate the appropriate CREATE TABLE query for this class."
   (unless (typep table 'dao-class)
@@ -342,7 +367,7 @@ (defun dao-table-definition (table)
    `(:create-table ,(dao-table-name table)
                    ,(loop :for slot :in (dao-column-slots table)
                           :unless (ghost slot)
-                          :collect `(,(slot-definition-name slot) :type ,(column-type slot)
+                       :collect `(,(slot-definition-name slot) :type ,(actual-col-type (column-type slot))
                                      ,@(when (slot-boundp slot 'col-default)
                                              `(:default ,(column-default slot)))))
                    ,@(when (dao-keys table)
