diff --git a/src/pgsql/pgsql-finalize-catalogs.lisp b/src/pgsql/pgsql-finalize-catalogs.lisp index 5a4eeef..5684100 100644 --- a/src/pgsql/pgsql-finalize-catalogs.lisp +++ b/src/pgsql/pgsql-finalize-catalogs.lisp @@ -15,6 +15,8 @@ (in-package #:pgloader.pgsql) (defun finalize-catalogs (catalog variant) + "Finalize the target PostgreSQL catalogs, dumbing down datatypes when the + target actually is Redshift rather than core PostgreSQL." ;; ;; For Core PostgreSQL, we also want to find data types names that have ;; no Btree support and fetch alternatives. This allows for supporting @@ -30,7 +32,9 @@ ;; (adjust-data-types catalog variant)) -(defgeneric adjust-data-types (catalog variant)) +(defgeneric adjust-data-types (catalog variant) + (:documentation + "Adjust PostgreSQL data types depending on the variant we target.")) ;;; ;;; Nothing needs to be done for PostgreSQL variant :pgdg, of course. diff --git a/src/sources/pgsql/pgsql-cast-rules.lisp b/src/sources/pgsql/pgsql-cast-rules.lisp index 6ac37ee..6c0690e 100644 --- a/src/sources/pgsql/pgsql-cast-rules.lisp +++ b/src/sources/pgsql/pgsql-cast-rules.lisp @@ -36,13 +36,16 @@ pgloader.catalog::extra) field (let* ((ctype (pgsql-column-ctype field)) + (extra (when (and (stringp (column-default field)) + (search "identity" (column-default field))) + :auto-increment)) (pgcol (apply-casting-rules nil pgloader.catalog::name pgloader.catalog::type-name ctype pgloader.catalog::default pgloader.catalog::nullable - pgloader.catalog::extra))) + extra))) ;; re-install our instruction not to transform default value: it comes ;; from PostgreSQL, and we trust it. (setf (column-transform-default pgcol) @@ -55,10 +58,16 @@ ((and (stringp default) (string= "NULL" default)) :null) - ((and (stringp default) - (or (string= "getdate()" default))) + ((and (stringp default) (string= "getdate()" default)) :current-timestamp) + ;; get rid of the identity default value, we already added + ;; an hint in the column-extra field. + ;; + ;; "identity"(347358, 0, ('1,1'::character varying)::text) + ((and (stringp default) (search "identity" default)) + :null) + (t (column-default pgcol)))) ;; we usually trust defaults that come from PostgreSQL... but we