Allow package prefix in CAST ... USING clause.

Also, in passing, ass a new transformation function for MySQL allowing
to transform from varbinary to text.
This commit is contained in:
Dimitri Fontaine 2016-02-04 16:05:53 +01:00
parent 782561fd4e
commit c108b85290
5 changed files with 47 additions and 11 deletions

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "PGLOADER" "1" "January 2016" "ff" ""
.TH "PGLOADER" "1" "February 2016" "ff" ""
.
.SH "NAME"
\fBpgloader\fR \- PostgreSQL data loader
@ -1758,7 +1758,7 @@ When loading from a \fBMySQL\fR database, the following options are supported, a
\fIinclude drop\fR
.
.IP
When this option is listed, pgloader drops all the tables in the target PostgreSQL database whose names appear in the SQLite database\. This option allows for using the same command several times in a row until you figure out all the options, starting automatically from a clean environment\. Please note that \fBCASCADE\fR is used to ensure that tables are dropped even if there are foreign keys pointing to them\. This is precisely what \fBinclude drop\fR is intended to do: drop all target tables and recreate them\.
When this option is listed, pgloader drops all the tables in the target PostgreSQL database whose names appear in the MySQL database\. This option allows for using the same command several times in a row until you figure out all the options, starting automatically from a clean environment\. Please note that \fBCASCADE\fR is used to ensure that tables are dropped even if there are foreign keys pointing to them\. This is precisely what \fBinclude drop\fR is intended to do: drop all target tables and recreate them\.
.
.IP
Great care needs to be taken when using \fBinclude drop\fR, as it will cascade to \fIall\fR objects referencing the target tables, possibly including other tables that are not being loaded from the source DB\.
@ -2945,6 +2945,12 @@ The SQL Server driver receives data fo type uniqueidentifier as byte vector that
.IP
Converts a unix timestamp (number of seconds elapsed since beginning of 1970) into a proper PostgreSQL timestamp format\.
.
.IP "\(bu" 4
\fIvarbinary\-to\-string\fR
.
.IP
Converts binary encoded string (such as a MySQL \fBvarbinary\fR entry) to a decoded text, using the table\'s encoding that may be overloaded with the \fIDECODING TABLE NAMES MATCHING\fR clause\.
.
.IP "" 0
.
.SH "LOAD MESSAGES"

View File

@ -2318,6 +2318,12 @@ The provided transformation functions are:
Converts a unix timestamp (number of seconds elapsed since beginning of
1970) into a proper PostgreSQL timestamp format.
- *varbinary-to-string*
Converts binary encoded string (such as a MySQL `varbinary` entry) to a
decoded text, using the table's encoding that may be overloaded with the
*DECODING TABLE NAMES MATCHING* clause.
## LOAD MESSAGES
This command is still experimental and allows receiving messages via

View File

@ -92,16 +92,29 @@
:drop-not-null drop-not-null))))
(defun function-name-character-p (char)
(or (member char #.(quote (coerce "/:.-%" 'list)))
(or (member char #.(quote (coerce "/.-%" 'list)))
(alphanumericp char)))
(defrule function-name (* (function-name-character-p character))
(:text t))
(defrule function-name (+ (function-name-character-p character))
(:lambda (fname)
(text fname)))
(defrule cast-function (and kw-using function-name)
(:lambda (function)
(bind (((_ fname) function))
(intern (string-upcase fname) :pgloader.transforms))))
(defrule package-and-function-names (and function-name
(or ":" "::")
function-name)
(:lambda (pfn)
(bind (((pname _ fname) pfn))
(intern (string-upcase fname) (find-package (string-upcase pname))))))
(defrule maybe-qualified-function-name (or package-and-function-names
function-name)
(:lambda (fname)
(typecase fname
(string (intern (string-upcase fname) :pgloader.transforms))
(symbol fname))))
(defrule cast-function (and kw-using maybe-qualified-function-name)
(:destructure (using symbol) (declare (ignore using)) symbol))
(defun fix-target-type (source target)
"When target has :type nil, steal the source :type definition."

View File

@ -69,7 +69,8 @@
byte-vector-to-bytea
sqlite-timestamp-to-timestamp
sql-server-uniqueidentifier-to-uuid
sql-server-bit-to-boolean))
sql-server-bit-to-boolean
varbinary-to-string))
;;;
@ -314,3 +315,10 @@
((string= "((1))" bit-string-or-integer) "t")
(t nil)))))
(defun varbinary-to-string (string)
(let ((babel::*default-character-encoding*
(or qmynd::*mysql-encoding*
babel::*default-character-encoding*)))
(etypecase string
(string string)
(vector (babel:octets-to-string string)))))

View File

@ -28,7 +28,10 @@ LOAD DATABASE
column ip.ip_address to inet keep not null drop typemod,
type decimal when (= precision 1) to boolean drop typemod
type decimal when (= precision 1) to boolean drop typemod,
-- type varbinary to text drop typemod using babel:octets-to-string
type varbinary to text drop typemod using varbinary-to-string
MATERIALIZE VIEWS nonexisting,
d as $$