-
-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cast fields to numeric or other types in a fixed type data loader file using pgloader #245
Comments
It is possible, either by sending directly text representation of numeric types, or by using transformation functions on the source data when necessary. Please consider posting error messages of what you get when you try so that I can better help you here. |
Thanks for your response. Yes, pgloader loaded in text representations into numeric columns successfully. Was also wondering about the best way to convert a date format like "08-04-201500:00" before loading. |
To add to my date casting question (08-04-201500:00 to timestamptz), I tried the following.
This threw the error (Please ignore any line numbers as I am using a working load script:
How would I pass in the required date format? |
See https://github.com/dimitri/pgloader/blob/master/test/fixed.load for an example of that. Basically there's no
|
Hi Dimitri Thanks for responding again. I tried using the following format:
What would you suggest? Thanks |
Ok, several problems here, several of those I should fix in pgloader itself. First, you need to quote the parameter list, using e.g. The current best option is then to write your own date parsing facility and load it from the command line, as in the following example:
And the files I've been using, first (in-package #:pgloader.transforms)
(defun parse-date-format
(date-string
&optional (format '((:year 6 10)
(:month 3 5)
(:day 0 2)
(:hour 10 12)
(:minute 13 15)
(:seconds 13 15))))
"Apply this function when input date in like '20041002152952'"
;; only process non-zero dates
(declare (type (or null string) date-string))
(cond ((null date-string) nil)
((string= date-string "") nil)
(t
(destructuring-bind (&key year month day hour minute seconds
&allow-other-keys)
(loop
for (name start end) in format
append (list name (subseq date-string start end)))
(if (or (string= year "0000")
(string= month "00")
(string= day "00"))
nil
(format nil "~a-~a-~a ~a:~a:~a"
year month day hour minute seconds)))))) And the load file,
|
Hi Dimitri |
Cool, closing the issue then! Thanks. |
This is not an issue but a question. Not sure whether this is the right place, so, please let me know if I should post it elsewhere.
Is it possible to cast fields to numeric or other types in a fixed type data loader file using pgloader?
I have a working .load file for pgloader which works if all the data types are text. However, I haven't been able to use pgloader to cast the field values to any other data type. Is it possible to do this either using a .load file or the pgloader command line? Working script with values removed below:
The text was updated successfully, but these errors were encountered: