Implement support for Redshift "identity" columns.

At this stage we don't even parse the details of the Redshift identity such
as the seed and step values and consider them the same as a MySQL
auto_increment extra description field.

Fixes #860 (again).
This commit is contained in:
Dimitri Fontaine 2018-11-09 22:41:14 +01:00
parent 794bc7fc64
commit 6c80404249
2 changed files with 17 additions and 4 deletions

View File

@ -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.

View File

@ -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