postgresql-copy

ERROR: COPY delimiter must be a single one-byte character

不问归期 提交于 2019-12-18 04:15:10
问题 I want to load the data from a flat file with delimiter "~,~" into a PostgreSQL table. I have tried it as below but looks like there is a restriction for the delimiter. If COPY statement doesn't allow multiple chars for delimiter, is there any alternative to do this? metadb=# \COPY public.CME_DATA_STAGE_TRANS FROM 'E:\Infor\Outbound_Marketing\7.2.1\EM\metadata\pgtrans.log' WITH DELIMITER AS '~,~' ERROR: COPY delimiter must be a single one-byte character \copy: ERROR: COPY delimiter must be a

How to tell if record has changed in Postgres

馋奶兔 提交于 2019-12-17 20:24:38
问题 I have a bit of an "upsert" type of question... but, I want to throw it out there because it's a little bit different than any that I've read on stackoverflow. Basic problem. I'm working on moving from mysql to PostgreSQL 9.1.5 (hosted on Heroku). As a part of that, I need to import multiple CSV files everyday. Some of the data is sales information and is almost guaranteed to be new and need to be inserted. But, other parts of the data is almost guaranteed to be the same. For example, the csv

Can COPY be used with a function?

☆樱花仙子☆ 提交于 2019-12-11 18:22:51
问题 I've been tasked with profiling a postgresql database. The first requirement is to see how fast records can be added, with all possible external bottlenecks removed, in order to find our theoretical limit. At first I created a csv file with sample data and read it in with the COPY function. Now, all records are added via a function update_or_add() . Is it possible to use COPY along with update_or_add() or is there a better solution that I haven't considered? 回答1: Rather than "for each row

importing data with commas in numeric fields into redshift

杀马特。学长 韩版系。学妹 提交于 2019-12-11 01:27:53
问题 I am importing data into redshift using the SQL COPY statement. The data has comma thousands separators in the numeric fields which the COPY statement rejects. The COPY statement has a number of options to specify field separators, date and time formats and NULL values. However I do not see anything to specify number formatting. Do I need to preprocess the data before loading or is there a way to get redshift to parse the numbers corerctly? 回答1: Import the columns as TEXT data type in a

syntax for COPY in postgresql

拈花ヽ惹草 提交于 2019-12-04 02:56:11
问题 INSERT INTO contacts_lists (contact_id, list_id) SELECT contact_id, 67544 FROM plain_contacts Here I want to use Copy command instead of Insert command in sql to reduce the time to insert values. I fetched the data using select operation. How can i insert it into a table using Copy command in postgresql. Could you please give an example for it?. Or any other suggestion in order to achieve the reduction of time to insert the values. 回答1: As your rows are already in the database (because you

COPY command: copy only specific columns from csv

二次信任 提交于 2019-12-01 16:01:41
问题 I had a question surrounding the COPY command in PostgreSQL. I have a CSV file that I only want to copy some of the columns values into my PostgreSQL table. Is it possible to do this? I am familiar with using the COPY command to copy all of the data from a CSV into a table using the header to map to the column names but how is this possible when I only want some of the columns? 回答1: Either pre-process the CSV file, or (what I probably would do) import into a temporary copy of the target table

syntax for COPY in postgresql

笑着哭i 提交于 2019-12-01 14:51:25
INSERT INTO contacts_lists (contact_id, list_id) SELECT contact_id, 67544 FROM plain_contacts Here I want to use Copy command instead of Insert command in sql to reduce the time to insert values. I fetched the data using select operation. How can i insert it into a table using Copy command in postgresql. Could you please give an example for it?. Or any other suggestion in order to achieve the reduction of time to insert the values. As your rows are already in the database (because you apparently can SELECT them), then using COPY will not increase the speed in any way. To be able to use COPY

Delete rows of a table specified in a text file in Postgres

此生再无相见时 提交于 2019-12-01 08:51:33
I have a text file containing the row numbers of the rows that should be deleted in my table like this: 3 32 40 55 [...] How can I get a PostgreSQL compatible SQL statement which deletes each of these rows from my table using the text file? Doing it once could look like this: CREATE TEMP TABLE tmp_x (nr int); COPY tmp_x FROM '/absolute/path/to/file'; DELETE FROM mytable d USING tmp_x WHERE d.mycol = tmp_x.nr; DROP TABLE tmp_x; For repeated use, wrap it into a plpgsql function with file-path / table name / column name as parameters. If table or column name are dynamic you have to use EXECUTE

Correct way to use copy Postgres jdbc

泄露秘密 提交于 2019-12-01 00:27:47
Unable to use copy command with jdbc Postgres. Whats wrong with the below code snippet sample. public boolean loadReportToDB(String date) { // TODO Auto-generated method stub Connection connection = DBUtil.getConnection("POSTGRESS"); String fileName = "C:/_0STUFF/NSE_DATA/nseoi_" + date + ".csv"; String sql = "\\copy fno_oi FROM 'C:\\_0STUFF\\NSE_DATA\\nseoi_27102017.csv' DELIMITER ',' CSV header"; try { PreparedStatement ps = connection.prepareStatement(sql); System.out.println("query"+ps.toString()); int rowsaffected = ps.executeUpdate(); System.out.println("INT+" + rowsaffected); return

Problems while importing a txt file into postgres using php

假如想象 提交于 2019-11-30 23:54:59
I am trying to import a txt/csv file into my postgres database from php using "\copy" command. I cannot use COPY instead of \copy as I need it to execute as a psql client. My code is: $query = '\\'.'copy data1 FROM "data1.txt" WITH CSV HEADER DELIMITER AS "," QUOTE AS "^"'; $result = pg_query($conn,$query); if (!$result) { echo "cannot copy data\n"; } else { echo "SUCCESS!"; } When I run this php file, I get this error: PHP Warning: pg_query(): Query failed: ERROR: syntax error at or near "\" LINE 1: \copy data1 FROM "data1.txt" WITH ... ^ in script.php on line 30 Actually, you cannot run