Questions tagged [copy]

COPY is a PostgreSQL SQL statement for bulk loading tables and fetching table data or query results

Filter by
Sorted by
Tagged with
0 votes
0 answers
17 views

How do I use COPY FROM on a backup file with multiple tables?

I used this command to backup my "supplies" table: COPY supplies (id, price, ...) FROM 'C:\Users\MyCompany\Desktop\database03-01-2022.sql'; But now, I would like to write three more tables' ...
user avatar
0 votes
1 answer
21 views

attribute 51 of type users has wrong type

I'm trying to import data to a pg table from a csv file. The error I get is: $ psql -U postgres -c "COPY users (first_name) FROM '/users.csv' (FORMAT csv)" ERROR: attribute 51 of type users ...
user avatar
  • 289
1 vote
1 answer
525 views

unterminated CSV quoted field when to import csv data file into postgresql

Create a table : CREATE TABLE num ( id serial NOT NULL , adsh VARCHAR(20) NOT NULL, tag VARCHAR(256) NOT NULL, version VARCHAR(20) NOT NULL, coreg VARCHAR(256), ddate date NOT ...
user avatar
  • 126
0 votes
2 answers
32 views

Export colums containing (geo)JSON elements to CSV while keeping the JSON double quotes properly

I want to export using copy 5 columns of a table, 3 of them contain ID, text and timestamp values but 2 of them contain JSON and GeoJSON elements, e.g.: // Please, note the non-quoted string Value1 /...
user avatar
  • 216
0 votes
1 answer
61 views

Insert from select without losing progress in the middle by Postgresql? "INSERT INTO ... SELECT ... WHERE ... AND NOT EXISTS (...)"

Is it possible to move data to the new table sourcing other tables without losing progress in the middle? I think of plpgsql that read data by chunks and commit after every N inserts... If the process ...
user avatar
  • 429
-1 votes
1 answer
240 views

Why can't copy data into csv file with double quotes?

The data can be exported with single quote in copy command: COPY mytest TO '/tmp/test.csv' DELIMITER ',' CSV HEADER; COPY 5 With double quotes: COPY mytest TO "/tmp/test.csv" DELIMITER ',' ...
user avatar
  • 126
0 votes
1 answer
21 views

Error with non-standard identifier in \copy command [closed]

Would like to be able to add characters like '-' in the schema name when running COPY command in PostgreSQL. Any way to get around this? psql -d postgres -c "\COPY (SELECT * FROM test-schema....
user avatar
  • 103
0 votes
2 answers
448 views

How to quote arrays in postgres copy statement to inser into JSON field

I have some data that looks like this: id,bo,c,url 1,"some text here", 22, "[{'id': 'NfKA3', 'u': 'https://somewebsite.com'}]" 2, "more text", 83, "[{'id': 'W3nAl', '...
user avatar
  • 211
0 votes
1 answer
284 views

Most efficient method to import bulk JSON data from different sources in postgresql?

I need to import data from thousands of URLs, here is an example of the data: [{"date":"20201006T120000Z","uri":"secret","val":"1765.756"},{...
user avatar
0 votes
1 answer
962 views

postgresql copy comand with date in filename

I have a query and want the output in a .csv file with today's date and time in the name (I am using PostgreSQL v12). COPY (SELECT * FROM mytable) TO 'C:\Users\me\mylocation\filename_date_time.csv' ...
user avatar
4 votes
1 answer
2k views

Postgres COPY with on conflict ignore - possible?

I want to add on conflict ignore to the Postgres copy command. I know I can copy the data to a table without unique index /primary key and then use insert with the on conflict syntax. But I wanted to ...
user avatar
  • 373
2 votes
3 answers
1k views

Postgres COPY with multiple small chunks

In postgres, we can do COPY to export the data into file. But all the data will be saved into a file. But I want to chunk that file into small files. We can do this after the export. But is there a ...
user avatar
  • 1,688
0 votes
2 answers
64 views

Using COPY in Postgres

I know COPY is the best utility to export the data from a table or a query to output files. But if we are doing an export like \COPY (select * from table) to '/tmp/file.csv' WITH CSV; How its ...
user avatar
  • 1,688
2 votes
1 answer
181 views

Load text column to postgres

I use the following to load data into postgres \copy tab FROM /tmp/file DELIMITER E'\t' QUOTE E'\b' NULL AS '\N' CSV Usually I select the data from a source db echo "select * from tab" | ...
user avatar
  • 373
0 votes
1 answer
62 views

Why doesn't the $1 syntax work for all queries?

I tried to do this: COPY postgres_log FROM $1 WITH csv; And with a separately sent file path, like I make all normal queries (SELECT/UPDATE/INSERT/DELETE). However, it gives: ERROR: syntax error at ...
user avatar
3 votes
1 answer
1k views

How to call from a shell program a postgresql COPY FROM FILE command, passing the path of the FILE as an argument?

I am trying to run, via a linux shell script, a Postgresql command that reads a CSV and updates a table with it. The difficulty I am facing, is that this shell script has to pass an argument to the ...
user avatar
0 votes
0 answers
100 views

Tuning postgres so it's optimized for bulk COPY imports

I am using the COPY command of Postgres to bulk insert data once a minute from an in-memory CSV file. I written the COPY code so that it performs the COPY's in parallel on separate db connections. My ...
user avatar
1 vote
0 answers
284 views

PostgreSQL COPY - Generated columns cannot be used in COPY

Im trying to import a SQL dump file for a table (A COPY command dump file). The table has a generated column. While restoring the dump Im getting this error. ERROR: column "call_status" is ...
user avatar
  • 1,688
0 votes
0 answers
491 views

PostgreSQL - pgAdmin 4 - COPY command not working with Schema

When trying to use the COPY command in pgAdmin 4 to copy a table from my database into a CSV file on disk copy Administrative.REGIONS TO 'd:\temp\regions.csv' with csv header I get the following ...
user avatar
0 votes
1 answer
328 views

How to copy user rights and roles from one user to another

I require a PL/SQL script that copies all of a user's rights, roles and mandates from one user to another. I am using Oracle 12c.
user avatar
0 votes
2 answers
3k views

How to import multiple CSV files to a postgres table using pgadmin or other method?

I'm looking to import a folder of over 100+ csv files into one table on PostgreSQL using pgadmin. I have the following script but is there a way to change the file path to all csvs? COPY schema.table ...
user avatar
0 votes
1 answer
626 views

Copy MySQL User but change HostName

I am migrating to a docker MariaDB setup and all my users were created w/ "Localhost". From what I read and tested ironically '%' excludes localhost. I want to copy my existing users adding a second ...
user avatar
0 votes
1 answer
114 views

vertica/postgres copy text to binary column

Until now I used Oracle to store xml file in blob data type column. Is there any option in Vertica to copy xml file into binary column? I saw there is varbinary data type but, I haven't succeeded to ...
user avatar
  • 103
0 votes
2 answers
34 views

COPY Command spawning multiple processes

I have a lengthy data pipeline that imports a CSV, creates a sequence of dependent views and then exports the results using COPY as a CSV. This process had been working fine, completing in around 30-...
user avatar
  • 211
1 vote
3 answers
193 views

MS SQL 2008 R2 - How to use a production database through dev/test environments or how to copy a SQL schema and all its data to another

We currently have 3 Windows Server 2008 R2 VM identically build for Sage x3 v6.5, one for production/formation/budget database, a second one for QA (qualification) and a third one for dev & tests. ...
user avatar
0 votes
0 answers
124 views

Firebird begin backup and forced writes off, timestamp update delayed

We have a Firebird database that's almost 200 Gbyte in sice, and for performance we have forced writes off. Please don't debate the risks of forced writes, we are aware of them. This is Firebird 3.0.4 ...
user avatar
1 vote
2 answers
400 views

Large database backup files integrity check after or before copy

I was trying to copy large database backup files(appx. 2TB each) to different region using robocopy. But I have noticed the speeds are drastically slow when using the switch /Z. So I have removed this ...
user avatar
0 votes
2 answers
81 views

PostgreSQL dump distinct column without memory consumption

I'm trying to dump csv of distinct varchar(43) column to file, table has around billion rows, select distinct command either runs out of memory and command is aborted or server just closes all ...
user avatar
0 votes
2 answers
3k views

Importing plain (raw) files into a postgres table (bytea and large objects)

What is a good way to insert/copy plain files into a postgres table, preferrably using the psql command-line? In my case the files are a bunch of eMails from Maildir archives, so I tried to use COPY: ...
user avatar
  • 115
2 votes
1 answer
411 views

PostgreSQL Copy command internals

I need to know some internals about the copy command in PostgreSQL 10. In particular I need to know if the copy from into a remote database makes batch insertions. If so, what is the default ...
user avatar
  • 23
3 votes
1 answer
124 views

Is it possible to load data into Postgres using COPY, where the data includes a SELECT statement?

(I think the answer is probably "no", but I haven't managed to find anything where anyone tried to do this. Which maybe is a sign in itself). So, I have a parent and child table than I'm generating ...
user avatar
  • 59
0 votes
1 answer
497 views

Can we copy data from 1 text file to 2 postgresql tables?

I have a text file with some data and I have two similar tables in my postgresql database. Is it possible to copy a part of the data present in the file, say first 10 lines, to the first table and the ...
user avatar
  • 47
0 votes
0 answers
38 views

Can copy command in postgresql append data to a file? [duplicate]

I want to add some data from a postgresql table to a text file. But already some data is present in the file. I do not want to delete that data. Is it possible? The questions asked earlier were the ...
user avatar
  • 47
0 votes
2 answers
137 views

Can't see process progress, machine getting slow trying to import 500 million records

Working environment: PostgreSQL 12.0, Ubuntu 18.10, 4GB memory, i5-3230M CPU @ 2.60GHz × 4, Os 64 bits I'm trying to import a .csv file with more than 500 million records into a PostgreSQL db table, ...
user avatar
  • 63
1 vote
1 answer
1k views

Parse a unix/epoch value as a `TIMESTAMP` in PostgreSQL

PostgreSQL's COPY command is useful to quickly import lots of data, and the data must be in the textual representation for the datatype. I am importing lots of data, includes a timestamp column, but ...
user avatar
2 votes
1 answer
2k views

Improve speed of COPY COMMAND in postgres

I would like to understand if increasing work_mem does help improving the speed of the COPY command. Does COPY use work_mem or maint_work_mem extensively?
user avatar
  • 425
0 votes
1 answer
79 views

Copy Data from Two different databases with FK relation

So the situation is as follow: I have production DB called DB1 which has huge data, around 250 GB. I have Test DB called DB2 on my local machine which has the same schema as the production DB but ...
user avatar
  • 139
0 votes
2 answers
90 views

Get value from one field, and paste it in to a new column

I'm relatively new to Microsoft Access, and just a beginner with SQL programming. I have a table in MS Access. It is an import from a .txt file. In the first column There is a String with a Number or ...
user avatar
2 votes
4 answers
3k views

Copy table from one server to another including keys and indexes

I have been working on a small project for about two weeks. We want to consolidate a few tables from several remote server databases in order to run queries and reports on separate from the live ...
user avatar
  • 21
0 votes
0 answers
53 views

How to copy/export part of my SQL database

So I have this huge live SQL database. I want to do some testing so I thought to export it, however, it is around 200 GB which is impossible to export. I thought maybe I export the schema of it and ...
user avatar
  • 139
2 votes
3 answers
2k views

Postgres \copy command into single column without delimiter

I am trying to import big fixed length files into Postgres and I am using the copy command and a staging table following this guide. The problem is that this files has a lot of different characters ...
user avatar
1 vote
1 answer
59 views

The simplest way to copy sql tables from one database to another?

So I have been logged into two different database. I want to copy one table from the first database to the other one with its content. I want to overwrite the content of the destination one (Because I ...
user avatar
  • 139
0 votes
0 answers
28 views

regularly calculating data and then loading to production database

I have a Postgres database running a small website. Most of the tables in the database are calculated values derived from various input data. This input data is updated approximately monthly. The ...
user avatar
6 votes
1 answer
4k views

Fastest way to extract full table in Postgres

I'm trying to dump a table with 50M records to a file, and my goal is to reduce the time in which this action is performed. I usually use the COPY metrics TO 'metrics.csv' DELIMITER ',' CSV; This ...
user avatar
  • 767
3 votes
2 answers
1k views

Log Shipping Copy Job Fails once in a while

I have configured log shipping at multiple database server with monitored server(separate server) and all of them are running fine without any issues. One particular server has 7 database and the ...
user avatar
2 votes
1 answer
261 views

Best way to copy data to other location without blocking source

I have a production database with some data I need to copy to other location, either another database on the same server or another server. The DB size is huge and I don't need all the data on the DB,...
user avatar
0 votes
1 answer
1k views

SELECT vs COPY (SELECT) TO STDOUT

I need to read more rows than fit in memory, resonably fast. I see two options: SELECT ... where my bindings use a cursor to stream the rows; COPY (SELECT ...) TO STDOUT (FORMAT binary) where my ...
user avatar
  • 109
0 votes
2 answers
49 views

Copying all columns of a row from table into another?

I would like to keep the history of a table using SQL queries without triggers. The simplest way to do that is to fire a SELECT and INSERT into the history table like below: INSERT INTO history (...
user avatar
  • 737
1 vote
1 answer
843 views

How to copy selected table data from sql server to mysql on a daily basis? [closed]

I am having a retail pos application with MSSQL database. Now I need to transfer selected table data from SQL server to MYSQL database on a daily basis like job. How to achive this?
user avatar
  • 19
-2 votes
1 answer
4k views

Using Postgres \COPY function with TSV format

I am getting ERROR: COPY format "tsv" not recognized when trying to copy file contents with psql \copy function. For some reason Postgres does not know TSV format? Command that I am running is: psql -...
user avatar