pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedproblems importing from csv
4+ messages / 4 participants
[nested] [flat]
* problems importing from csv
@ 2019-09-13 18:22 stan <stanb@panix.com>
0 siblings, 2 replies; 4+ messages in thread
From: stan @ 2019-09-13 18:22 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I am trying to import some data from spreadsheets. Included in the data
sets are US monetary values. These appear in the CSV file, like this: $1.00
The column is defined like this: NUMERIC(5,2) NOT NULL. When I try to
import this data using the \copy functionality, i get the following error;
stan@smokey:~/pm_db/live_data$ psql < import_employee.sql
ERROR: invalid input syntax for type numeric: "$1.00"
CONTEXT: COPY employee, line 2, column hourly_rate: "$1.00"
How can I work around this?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problems importing from csv
@ 2019-09-13 18:33 Melvin Davidson <melvin6925@gmail.com>
parent: stan <stanb@panix.com>
1 sibling, 0 replies; 4+ messages in thread
From: Melvin Davidson @ 2019-09-13 18:33 UTC (permalink / raw)
To: stan <stanb@panix.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
>ERROR: invalid input syntax for type numeric: "$1.00"
>CONTEXT: COPY employee, line 2, column hourly_rate: "$1.00"
Try changing the format of the column from currency to numeric BEFORE
exporting.
On Fri, Sep 13, 2019 at 2:22 PM stan <stanb@panix.com> wrote:
>
> I am trying to import some data from spreadsheets. Included in the data
> sets are US monetary values. These appear in the CSV file, like this: $1.00
> The column is defined like this: NUMERIC(5,2) NOT NULL. When I try to
> import this data using the \copy functionality, i get the following error;
>
> stan@smokey:~/pm_db/live_data$ psql < import_employee.sql
> ERROR: invalid input syntax for type numeric: "$1.00"
> CONTEXT: COPY employee, line 2, column hourly_rate: "$1.00"
>
> How can I work around this?
>
> --
> "They that would give up essential liberty for temporary safety deserve
> neither liberty nor safety."
> -- Benjamin Franklin
>
>
>
--
*Melvin Davidson*
*Maj. Database & Exploration Specialist*
*Universe Exploration Command – UXC*
Employment by invitation only!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problems importing from csv
@ 2019-09-13 19:45 Adrian Klaver <adrian.klaver@aklaver.com>
parent: stan <stanb@panix.com>
1 sibling, 1 reply; 4+ messages in thread
From: Adrian Klaver @ 2019-09-13 19:45 UTC (permalink / raw)
To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org
On 9/13/19 11:22 AM, stan wrote:
>
> I am trying to import some data from spreadsheets. Included in the data
What program?
Usually there is an option to save the raw values not the formatted
ones. In LibreOffice you uncheck the Save content as shown option.
> sets are US monetary values. These appear in the CSV file, like this: $1.00
> The column is defined like this: NUMERIC(5,2) NOT NULL. When I try to
> import this data using the \copy functionality, i get the following error;
>
> stan@smokey:~/pm_db/live_data$ psql < import_employee.sql
> ERROR: invalid input syntax for type numeric: "$1.00"
> CONTEXT: COPY employee, line 2, column hourly_rate: "$1.00"
>
> How can I work around this?
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problems importing from csv
@ 2019-09-20 04:01 Michael Lewis <mlewis@entrata.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 0 replies; 4+ messages in thread
From: Michael Lewis @ 2019-09-20 04:01 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: stan <stanb@panix.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>
>I am trying to import some data from spreadsheets. Included in the data
>sets are US monetary values. These appear in the CSV file, like this: $1.00
>The column is defined like this: NUMERIC(5,2) NOT NULL.
1) remove all $ characters from csv before import
OR
2) import into text field (perhaps in a temp table), remove $ characters,
cast value and insert into numeric field
By the way, there may be no benefit to specifying a max value of 99,999.99
if you can foresee a potential need for bigger values. For values that fit,
numeric(1000,2) will store numbers in the same bytes as a numeric(5,2)
field will. It just won't throw an error if large values are used in the
future.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-09-20 04:01 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-09-13 18:22 problems importing from csv stan <stanb@panix.com>
2019-09-13 18:33 ` Melvin Davidson <melvin6925@gmail.com>
2019-09-13 19:45 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-09-20 04:01 ` Michael Lewis <mlewis@entrata.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox