Import from .csv to PostgreSQL - mysql

I'm new in PostgreSQL. Have a working MySQL query making import from .csv:
LOAD DATA LOCAL INFILE '/home/d/docs/DB.csv'
INTO TABLE calculations.pricing FIELDS TERMINATED BY ','
ENCLOSED BY '"' LINES TERMINATED BY '\n';
How can I fix it working with Postgre. Thanks!

The COPY command is your friend.

Related

LOAD DATA LOCAL INFILE not working - File not found (MySQL Workbench)

I am using the below command to load an excel file to MySQL server:
LOAD DATA LOCAL INFILE 'GPMO_Resource_Download_report_CSV'
INTO TABLE gpmo_resource_download_report_1
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';
I have this file on the same machine at the below path:
C:\Users\aprakas2\Desktop\Task\GPMO_Resource_Download_report_CSV
Please suggest me how should I load this file ?
I think these SQL will useful to you.
If file has header row
LOAD DATA INFILE 'C:/Users/aprakas2/Desktop/Task/GPMO_Resource_Download_report_CSV'
INTO TABLE gpmo_resource_download_report_1
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
If file has no header row
LOAD DATA INFILE 'C:/Users/aprakas2/Desktop/Task/GPMO_Resource_Download_report_CSV'
INTO TABLE gpmo_resource_download_report_1
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Thank you.

How to import xls file in to MySQL table

I'm using ubuntu 14.04 operating system and I want to import excel sheet(.xls) in to database.
I am using phpmyadmin mysql administration tool. If any one can give me the commands to import xls to mysql I would be grateful.
Import CSV file in to MySQL Table
Change file type in to CSV
Create table according to excel column names
Place the csv file in /var/lib/mysql
Open phpmyadmin sql command pane:
Execute this sql command
LOAD DATA INFILE 'testlist.csv'
INTO TABLE TEST
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Use the load data capability. See
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Export CSV file in to MySQL Table
SELECT ... FROM ... WHERE ...
INTO OUTFILE 'testlist.csv'
FIELDS TERMINATED BY ','
Here is an example that produces a file in the comma-separated values (CSV) format used by many programs:
SELECT * INTO OUTFILE '/tmp/result.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;

How to import csv to mysql table?

Error: This query is just inserting the 1 line of file
LOAD DATA INFILE 'file.csv' INTO TABLE coords FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
And the file has 300k lines.
Columns are separeted by commas.
How is the coords created? Does it have 10 attributes for the data?
I just ran a quick test with a file containing six identical lines (using your data) and entered:
LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE coord FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
It read all 6 lines in.
I did this under Linux. If you're on Windows maybe you need '\r\n' (?).

CSV import omit a field

I'm trying to import a table from CSV file to phpMyAdmin.
This is my table:
1 |Evan|Chigur |Male|1987-05-25|codefiscale0123|Via Calatafini 17, Palermo, 23451|user#user.it|marco_r|ee11cbb19052e40b07aac0ca060c23ee
22 |Hank|Zappasorca|Male|1987-05-25|codefiscale0123|Via Calatafini 17, Palermo, 23451|user#user.it|marco_r|ee11cbb19052e40b07aac0ca060c23ee
When i try to fill my table with this, the first field is omitted.
I've already checked out the correspondences of the fields between the cvs and mysql table.
Can anyone help me?
i use this query:
LOAD DATA LOCAL INFILE 'C:\\wamp\\tmp\\php7E3C.tmp' REPLACE INTO TABLE `bw_users`FIELDS TERMINATED BY '|'ENCLOSED BY '"'ESCAPED BY '\\'LINES TERMINATED BY '*'
how does this work for you?
LOAD DATA INFILE 'C:\\wamp\\tmp\\php7E3C.tmp' REPLACE INTO TABLE bw_users
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
for windows change to
LINES TERMINATED BY '\r\n'

Importing data from Sybase to MySQL

I'm migrating an old Sybase database to a new MySQL db.
Since the moment that Sybase can export data to .dat files (something similar to new csv), I decided to use it.
The problem is that Sybase uses commas as column separator and commas in strings are ignored because are enclosed in '', but not in MySQL.
Is there a way to solve the problem? Here's my query:
LOAD DATA LOCAL INFILE 'C:\\UNLOAD\\166.dat'
INTO TABLE linea_col
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\r\n';
Thank you in advance.
If they are enclosed by single quotes try this:
LOAD DATA LOCAL INFILE 'C:\\UNLOAD\\166.dat'
INTO TABLE linea_col
COLUMNS TERMINATED BY ','
ENCLOSED BY '\''
LINES TERMINATED BY '\r\n';
If that doesn't work then you should do ENCLOSED BY '''' but I'm 99.99% certain the first is correct.
I'm not familiar with how DAT files may differ to CSV, but you can use CSV as the common format.
You can export from Sybase using BCP and forcing the output to use CSV format
bcp database.dbo.tbl_name out c:\temp\output.csv -c -t, -U user_name -P password -S server_name
Then import into MySQL with
load data local infile 'uniq.csv' into table tblUniq fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(uniqName, uniqCity, uniqComments)