Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

2 votes
1 answers
478 views
Bulk load data and provide row-by-row feedback
We want to allow our users to import CSV files containing many thousands of records to "pre-load" a particular table in our system. It's not strictly a one-time operation, it may be performed multiple times as they get feedback, tweak the CSV, and re-import. I understand that this is not a lot of da...
We want to allow our users to import CSV files containing many thousands of records to "pre-load" a particular table in our system. It's not strictly a one-time operation, it may be performed multiple times as they get feedback, tweak the CSV, and re-import. I understand that this is not a lot of data, relatively speaking. But, we want the operation to be atomic (this is a multi-user system other users may also be adding or modifying data) and we want to provide per-row feedback (like "Row 123 is a duplicate of item 'abc'"). I know that statements like COPY or tools like pg_bulkload can do the work very quickly, but this is user-interactive via our web app and we _require_ row-by-row feedback. Our naïve approach was to run sequential INSERT statements and to catch exceptions. Even though we're re-using a single connection, this makes separate calls and uses a separate transaction. This is taking _way_ too long.
for(var i = 0; i < rows.Count; i++)
{
    try
    {
        connection.Execute("INSERT INTO table1 VALUES (...)");
        // format a "successful" response
    }
    catch (PostgresException e)
    {
        // format a "failed" response based on exception details... 
    }
}
We tried creating a single INSERT statement with multiple VALUES, but this does not provide row-by-row feedback and it stops on the 1st error (I found no useful way to use ON CONFLICT here). We also tried sharing a transaction and running sequential statements but the transaction is "aborted" on the 1st error.
using(var tx = connection.BeginTransaction())
{
    for(var i = 0; i < rows.Count; i++)
    {
        try
        {
            connection.Execute("INSERT INTO table1 VALUES (...)", tx);
            // format a "successful" response
        }
        catch (PostgresException e)
        {
            // format a response based on the type of failure... 
        }
    }
}
I'm beginning to think that we need to run this entire operation _within_ the database in SQL. We have only one constraint right now, a NOT NULL UNIQUE "name" column. So the statuses would be something like... * "OK": the row inserted fine (return the new PRIMARY KEY "id" column) * "Conflict": the name in this row is a duplicate of an existing row either a row seen earlier in the CSV or already in the table (return the duplicate name) * "Bad Request": the name in this row is missing, empty, or all whitespace We also need to return the index (in insert order, I guess) in order to approximate the line number in the original CSV file. I'm thinking we need to INSERT into a temporary table and use something like row_number(). Given a CSV like this (name + some example columns, just to make the point)
name,region,code,set
A1,A,100,1
A2,A,101,1
A1,A,102,1
,B,200,2
C1,C,300,3
I would need responses like this: index | id | name | status ------|--------|--------|------- 1 | 100 | A1 | OK 2 | 101 | A2 | OK 3 | [null] | A1 | Conflict 4 | [null] | [null] | Bad Request 5 | 102 | C1 | OK Am I on the right path? Is this a workable solution or is there some other technique that would work better? Does it make sense to work the queries out by status? Like, rather than try to process one record at a time, can I try to find all of the bad requests 1st, then all of the duplicates, then all of the new rows (and insert them)? I'm fine with this response, we can always reorganize them in the application code. index | id | name | status ------|--------|--------|------- 4 | [null] | [null] | Bad Request 3 | [null] | A1 | Conflict 1 | 100 | A1 | OK 2 | 101 | A2 | OK 5 | 102 | C1 | OK Believe me, I'm asking around about the requirement, but it seems stuck for now &emdash; they really want to provide the user with specific row-by-row feedback. If I insert into a temporary staging table, can I run 3 set-based operations? One for bad requests, one for duplicates, and one for new records?
Anthony Mastrean (121 rep)
Jul 9, 2018, 05:32 PM • Last activity: Aug 1, 2025, 05:02 AM
0 votes
1 answers
2793 views
0 rows from the .csv (semi colon) are imported into MySQL Workbench
I am trying to import the .csv below (columns and 3 first records in txt in differenet blockquotes) into MySQL Workbench using the Table Data Import Wizard. I have tried many ways and realized that the issue lies with this particular .csv. I even used the LOAD DATA LOCAL INFILE statement with no suc...
I am trying to import the .csv below (columns and 3 first records in txt in differenet blockquotes) into MySQL Workbench using the Table Data Import Wizard. I have tried many ways and realized that the issue lies with this particular .csv. I even used the LOAD DATA LOCAL INFILE statement with no success using the terminal but things get complicated dipslaying different errors. > LOAD DATA LOCAL INFILE "C:\Users\user\Documents\Edu_research\SQL\Project_TED\talks_final_effort_new1.csv" INTO TABLE talks FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '/n' IGNORE 1 ROWS; At first I used delimiter ',' and strings enclosed with '"' but everything was messed up, probably because of a column with long text with commas and double quotes etc., and it could not identify the columns. So I changed the delimiter to ';' but the same happened. Then I kept the ';'. I tried for the 1st record and it was imported but for the rest of the records it didn't. I broke it down to 3 records (displayed below) used the settings below enter image description here and it showed this message again enter image description here I believe the "enclosed by" setting with '"' is the problematic beacuse there are some """ in the description column. I am not sure if I can deal with it not manually neither using TABLE IMPORT WIZARD or LOAD statement. > talk_id;title;speaker_1;all_speakers;occupations;about_speakers;views;recorded_date;published_date;event;native_lang;available_lang;comments;duration;topics;related_talks;url;description > 1;Averting the climate crisis;Al Gore;{0: 'Al Gore'};{0: ['climate advocate']};{0: 'Nobel Laureate Al Gore focused the world’s attention on the global climate crisis. Now he’s showing us how we’re moving towards real solutions.\r\n'};3523392;2/25/2006;6/27/2006;TED2006;en;"['ar', 'bg', 'cs', 'de', 'el', 'en', 'es', 'fa', 'fr', 'fr-ca', 'gl', 'gu', 'he', 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'lt', 'lv', 'mk', 'nl', 'pl', 'pt', 'pt-br', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sv', 'sw', 'th', 'tl', 'tr', 'uk', 'ur', 'vi', 'zh-cn', 'zh-tw']";272;977;"['alternative energy', 'cars', 'climate change', 'culture', 'environment', 'global issues', 'science', 'sustainability', 'technology']";"{243: 'New thinking on the climate crisis', 547: 'The business logic of sustainability', 2093: 'The state of the climate — and what we might do about it', 54715: 'How we can turn the tide on climate', 29968: 'The most important thing you can do to fight climate change: talk about it', 2339: ""Climate change is happening. Here's how we adapt""}";https://www.ted.com/talks/al_gore_averting_the_climate_crisis/ ;"With the same humor and humanity he exuded in ""An Inconvenient Truth,"" Al Gore spells out 15 ways that individuals can address climate change immediately, from buying a hybrid to inventing a new, hotter brand name for global warming." 92;The best stats you've ever seen;Hans Rosling;{0: 'Hans Rosling'};{0: ['global health expert; data visionary']};"{0: 'In Hans Rosling’s hands, data sings. Global trends in health and economics come to vivid life. And the big picture of global development -- with some surprisingly good news -- snaps into sharp focus.'}";14501685;2/22/2006;6/27/2006;TED2006;en;"['ar', 'az', 'bg', 'bn', 'bs', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fr', 'he', 'hi', 'hr', 'hu', 'id', 'is', 'it', 'ja', 'kn', 'ko', 'ku', 'lv', 'mk', 'ml', 'mn', 'nl', 'pl', 'pt', 'pt-br', 'ro', 'ru', 'sk', 'sr', 'sv', 'sw', 'ta', 'te', 'th', 'tr', 'uk', 'ur', 'vi', 'zh-cn', 'zh-tw']";628;1190;"['Africa', 'Asia', 'Google', 'demo', 'economics', 'global issues', 'health', 'statistics', 'global development', 'visualizations', 'math']";"{2056: ""Own your body's data"", 2296: 'A visual history of human knowledge', 620: 'Let my dataset change your mindset', 2806: ""Doesn't everyone deserve a chance at a good life?"", 2560: 'How Africa can keep rising', 1418: ""Let's put birth control back on the agenda""}";https://www.ted.com/talks/hans_rosling_the_best_stats_you_ve_ever_seen/ ;"You've never seen data presented like this. With the drama and urgency of a sportscaster, statistics guru Hans Rosling debunks myths about the so-called ""developing world.""" 7;Simplicity sells;David Pogue;{0: 'David Pogue'};{0: ['technology columnist']};"{0: 'David Pogue is the personal technology columnist for the New York Times and a tech correspondent for CBS News. He\'s also one of the world\'s bestselling how-to authors, with titles in the For Dummies series and his own line of ""Missing Manual"" books. '}";1920832;2/24/2006;6/27/2006;TED2006;en;"['ar', 'bg', 'de', 'el', 'en', 'es', 'fa', 'fr', 'he', 'hr', 'hu', 'it', 'ja', 'ko', 'nb', 'nl', 'pl', 'pt', 'pt-br', 'ro', 'ru', 'sr', 'tr', 'vi', 'zh-cn', 'zh-tw']";124;1286;"['computers', 'entertainment', 'interface design', 'media', 'music', 'performance', 'simplicity', 'software', 'technology']";"{1725: '10 top time-saving tech tips', 2274: 'The first secret of design is ... noticing', 172: 'Designing for simplicity', 2664: 'Meet the inventor of the electronic spreadsheet', 2464: 'The mind behind Linux', 1347: 'The secret structure of great talks'}";https://www.ted.com/talks/david_pogue_simplicity_sells/ ;"New York Times columnist David Pogue takes aim at technology’s worst interface-design offenders, and provides encouraging examples of products that get it right. To funny things up, he bursts into song." This .csv is a real trouble. I believe I have searched any possible link on the Internet to figure it out but still no success. What could be the problem here? I The only method i haven't used is via phpmyadmin but I don't think that the issue lies with the method/tool. Appreciate your help Thanks
transmod_kdtk (1 rep)
Apr 17, 2022, 08:51 PM • Last activity: Jul 28, 2025, 06:04 AM
0 votes
1 answers
827 views
importing csv file with ragged right format and " text qualifier
I'm importing csv files in ssis that are in a ragged right format, I've been able to create the columns perfectly fine but for some of the data rows it has included a " text qualifier into the data in the first column which makes the character count of each column out sync and pushes some characters...
I'm importing csv files in ssis that are in a ragged right format, I've been able to create the columns perfectly fine but for some of the data rows it has included a " text qualifier into the data in the first column which makes the character count of each column out sync and pushes some characters over to the next columns, the " text qualifier is also found in the last column of the same row by itself instead of the value being blank. These " text qualifiers are also not found in the original csv file, the flat file connection manager also does not let you use the text qualifier option when working with ragged right so i can't take them out that way. enter image description here
HappyCoder123 (25 rep)
Jan 26, 2021, 02:16 AM • Last activity: Jul 26, 2025, 11:04 AM
0 votes
1 answers
1114 views
BULK INSERT does not fail when file contains commas instead of semicolons when FIRSTROW > 1
I encountered an issue where I received a CSV file that supposed to be delimited by semicolons (;) but was delimited by commas (,). Bulk insert called by sqlcmd did not fail but did not insert either. I know that calling xp_cmdshell is not best practice but please don't comment on this. After invest...
I encountered an issue where I received a CSV file that supposed to be delimited by semicolons (;) but was delimited by commas (,). Bulk insert called by sqlcmd did not fail but did not insert either. I know that calling xp_cmdshell is not best practice but please don't comment on this. After investigation I found that it only fails (as expected) when FIRSTROW = 1, but I need a header inside the file. Table:
CREATE TABLE [dbo].[test_table](
	[id] [int] NULL,
	[title] [varchar](10) NULL,
	[val] [int] NULL
)
Format file:
12.0
3
1       SQLCHAR              0       4       ";"    1     "id"             ""
2       SQLCHAR              0       10      ";"    2     "title"          SQL_Latin1_General_CP1_CI_AS
3       SQLCHAR              0       4       "\r\n"     3     "val"            ""
Data file:
1,first,0
2,second,2
Bulk insert:
DECLARE @cmd VARCHAR(4000);
SET @cmd = 'sqlcmd -b -S  -Q "set nocount on; set dateformat dmy; bulk insert [test_db].[dbo].[test_insert] from ''C:\temp\test_table.csv'' with ( DATAFILETYPE = ''char'', TABLOCK, MAXERRORS = 1000, FIELDTERMINATOR = '';'', ROWTERMINATOR = ''\r\n'', BATCHSIZE = 100000, FORMATFILE = ''C:\temp\test_table.txt'', FIRSTROW = 2 );"';
EXEC xp_cmdshell @cmd;
owl (310 rep)
Dec 4, 2020, 03:03 PM • Last activity: Jul 13, 2025, 09:05 AM
1 votes
1 answers
1355 views
SQL in Access to add leading 0 in front of zip codes
for a project I am working with a table of zip-codes that I imported from a *.csv file, exported form Excel. Those zipcodes all have 5 numbers and are formatted as text within my database. Some of them should start with 0, however during the export/import process this 0 got lost, leaving me with zip...
for a project I am working with a table of zip-codes that I imported from a *.csv file, exported form Excel. Those zipcodes all have 5 numbers and are formatted as text within my database. Some of them should start with 0, however during the export/import process this 0 got lost, leaving me with zip-codes that only have 4 instead of 5 digits where the leading 0 went missing. Is there a way an SQL command might add this zero to strings only having 4 digits? Thank you
Titan (11 rep)
Mar 21, 2022, 01:05 PM • Last activity: Jun 29, 2025, 08:05 AM
3 votes
1 answers
601 views
Update foreign key from csv file
I am trying to set up a simple database for the first time using MySQL Workbench. I'd like to update the foreign keys of the `child` table based on the values of `parent_child.csv`. Here are the current MySQL tables I have right now. parent table id_num parent_id ------------------ 33 parent_1 29 pa...
I am trying to set up a simple database for the first time using MySQL Workbench. I'd like to update the foreign keys of the child table based on the values of parent_child.csv. Here are the current MySQL tables I have right now. parent table id_num parent_id ------------------ 33 parent_1 29 parent_2 46 parent_3 17 parent_4 ... ... child table id_num child_id parent_id_num -------------------------------- 22 child_1 NULL 13 child_2 NULL 52 child_3 NULL 76 child_4 NULL ... ... ... And here is what parent_child.csv looks like: parent_child.csv parent_id child_id -------------------- parent_1 child_3 parent_1 child_4 parent_2 child_1 ... ... Here is what I'd like the updated child table to be: child table id_num child_id parent_id_num -------------------------------- 22 child_1 29 13 child_2 NULL 52 child_3 33 76 child_4 33 ... ... ... Assume that not all parent_id and child_id's are in parent_child.csv. So not all child_id's get updated. How would I go about doing this? Would it require me to create a parent_child table in MySQL? Here's what I want to do in a nutshell: for every child_id in parent_child.csv: * get child_id's parent_id * find parent_id's id_num using parent table * replace child_id's foreign key (referred to as parent_id_num, set currently to NULL) with the found parent id's id_num
koreebay (31 rep)
Dec 11, 2015, 11:53 PM • Last activity: Jun 23, 2025, 08:08 AM
1 votes
1 answers
1053 views
How to Export MS SQL DB from Docker-Linux to Access format
I have a MS SQL database which is currently up and running on my Mac within a Docker container that is hosting the Ubuntu Linux version of MS SQL Server. I need to export the database to a format that can be imported into an Access (yes, *Access*) database. Alternatively, I would need to export all...
I have a MS SQL database which is currently up and running on my Mac within a Docker container that is hosting the Ubuntu Linux version of MS SQL Server. I need to export the database to a format that can be imported into an Access (yes, *Access*) database. Alternatively, I would need to export all 300+ tables to CSV, and hopefully would not need to do them one by one. Is there any way to export all tables en masse to CSV? But this is an alternative option. I still prefer the Access-compatible export since our new SIS vendor apparently uses it. Thanks!
zeeple (109 rep)
Mar 31, 2020, 07:20 PM • Last activity: Jun 10, 2025, 05:08 PM
0 votes
1 answers
265 views
merge multiple fields of csv file while running mysqlimport command
I have a mysql table like this +----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | roll_no | varchar(5...
I have a mysql table like this +----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | roll_no | varchar(50) | NO | MUL | NULL | | | marks | varchar(100) | YES | | NULL | | | academy | varchar(100) | YES | | NULL | | +----------------+--------------+------+-----+---------+----------------+ the marks column can have multiple numbers separated by comma like this 45,67,78,80, # First Example 34,56, # Second Example I have to run mysqlimport command such that the fields after the first fields till second-last fields should merge into marks column I tried something like this mysqlimport --fields-terminated-by=, --columns='roll_no, marks, academy' --ignore --local -u root -pxxxx result results.csv But extra fields (after 3rd one) gets truncated. How to handle such scenarios where the csv fields are dynamic
Anurag Sharma (101 rep)
Apr 16, 2015, 07:34 AM • Last activity: May 21, 2025, 08:05 PM
0 votes
1 answers
282 views
batch script to get all the tables in postgres database as csv
I have a remote postgresql database with a lot of schemas. I want to dump the tables that is specific schema as .CSV file for each table. I'm aware of the COPY command but I'm not sure how to write a batch script that will execute the COPY command.
I have a remote postgresql database with a lot of schemas. I want to dump the tables that is specific schema as .CSV file for each table. I'm aware of the COPY command but I'm not sure how to write a batch script that will execute the COPY command.
new_developer (1 rep)
Oct 14, 2023, 03:38 PM • Last activity: May 17, 2025, 08:02 AM
0 votes
2 answers
1939 views
How can I use pg_dump to export a single table to CSV that can then be imported by Oracle SQL Loader?
Thanks in advance for any help on this. **Problem Summary:** I'm looking for the most efficient way possible to export a single table from Postgres/Greenplum for a large number of records (100M+) so that it can be imported by Oracle SQL Loader. **Research Background:** I know from research thus far...
Thanks in advance for any help on this. **Problem Summary:** I'm looking for the most efficient way possible to export a single table from Postgres/Greenplum for a large number of records (100M+) so that it can be imported by Oracle SQL Loader. **Research Background:** I know from research thus far that the pg_dump utility is more efficient than Postgres COPY, so I do NOT want to use the COPY command. Using pg_dump has many pluses, and can: 1. Can use multiple threads/cores 2. Can dump a single table of output 3. but to CSV? **My Main Question:** The critical thing I can't figure out yet is how to get pg_dump to export to csv or fixed-width plain text output. **A sidebar question:** I can't seem to find a detailed description (other than, 'The pg_dump --format=custom means the data is compressed') of what exactly the "custom" pg_dump format does to the data. The word "custom" implies that the output should be to a controllable schema, but I haven't been able to locate documentation yet of how this works.
zigmoo (9 rep)
Oct 12, 2022, 04:39 PM • Last activity: May 14, 2025, 01:05 PM
0 votes
1 answers
1738 views
How to save a CSV file that adds double quotes to special characters that enables easy importing?
When I was importing a CSV file to MySql Workbench that had special characters like comma, brackets, etc., few rows that contained data containing special characters were getting missed (, )) etc). Therefore, my question is, how to save a CSV file that adds double quotes to special characters that e...
When I was importing a CSV file to MySql Workbench that had special characters like comma, brackets, etc., few rows that contained data containing special characters were getting missed (, )) etc). Therefore, my question is, how to save a CSV file that adds double quotes to special characters that enables easy importing?
Gaurang Agrawal (1 rep)
Jan 3, 2022, 04:07 AM • Last activity: May 3, 2025, 11:04 PM
1 votes
1 answers
3065 views
How do I import CSV UUID data into Postgres on the command line?
I'm using PostGres 10. I have this table > \d myapp_currencyprice; Table "public.myapp_currencyprice" Column | Type | Modifiers --------------------+--------------------------+----------- id | uuid | not null price | double precision | not null created | timestamp with time zone | not null currency_...
I'm using PostGres 10. I have this table > \d myapp_currencyprice; Table "public.myapp_currencyprice" Column | Type | Modifiers --------------------+--------------------------+----------- id | uuid | not null price | double precision | not null created | timestamp with time zone | not null currency_id | uuid | not null I have a CSV of data, which looks like id,price,created,currency_id fa9944a6-f622-499c-89b8-42534a541307,59451.41,2021-11-20 15:56:00-05,3965e495-d5a5-41ec-83fc-359545ca2716 13013751-d84a-441f-a19a-3c7b50c557d0,59474.17,2021-11-20 15:58:00-05,3965e495-d5a5-41ec-83fc-359545ca2716 but when I try and import the data on the command line, I get this error > PGPASSWORD=$DB_PASS psql -U $DB_USER -d $DB_NAME -c "\copy myapp_currencyprice FROM '/tmp/prices.csv' delimiter ',' csv" ERROR: invalid input syntax for uuid: "id" CONTEXT: COPY myapp_currencyprice, line 1, column id: "id" what's the right way to import data from a CSV into a PostGres table?
Dave (753 rep)
Dec 12, 2021, 12:58 AM • Last activity: Apr 28, 2025, 03:06 PM
4 votes
5 answers
4300 views
import 100 csv files into postgresql
I have a 100 csv files named sequentially 1,2,3....100.csv I copy the csv files with this script: COPY location FROM 'C:\Program Files\PostgreSQL\9.5\data\&#180;1.csv' DELIMITER ','; I would to execute the COPY with a single script that covers all the files (1,2,3 .... 100.csv). I use pgadminIII on...
I have a 100 csv files named sequentially 1,2,3....100.csv I copy the csv files with this script: COPY location FROM 'C:\Program Files\PostgreSQL\9.5\data\´1.csv' DELIMITER ','; I would to execute the COPY with a single script that covers all the files (1,2,3 .... 100.csv). I use pgadminIII on MS Windows
michal (103 rep)
Apr 1, 2017, 04:17 PM • Last activity: Apr 24, 2025, 07:46 AM
3 votes
4 answers
3260 views
Best DB structure for large CSVs?
I have previously posted on [stackoverflow][1], however, I have been directed here. I'm getting to the stage where I need to analyse lots of flat CSVs: - Read-in around 500GB of CSVs (e.g. daily data split by month) - Group the data (e.g. by month or year) - Output the aggregated data as a small CSV...
I have previously posted on stackoverflow , however, I have been directed here. I'm getting to the stage where I need to analyse lots of flat CSVs: - Read-in around 500GB of CSVs (e.g. daily data split by month) - Group the data (e.g. by month or year) - Output the aggregated data as a small CSV I wasn't sure whether sqlite was the right package for this (adding CSVs to it appears to take a long time and as in my link above after a certain size I can't access the database) and whether I should consider something else like PostgreSQL or Microsoft SQL Server? I'm looking to invest in a hardware/software platform for this (e.g. SSD, RAID, Microsoft SQL Server) and was hoping for some information on where to begin. Particularly, if PostgreSQL is a possibility - is there a similar way to quickly import CSVs like here: https://blog.netnerds.net/2015/01/powershell-high-performance-techniques-for-importing-csv-to-sql-server/ **Edit (08/10/15):** I'm testing out uploading the data into a PostgreSQL database and am averaging 16 minutes per 10GB CSV. My issue is that some of my columns are very big so I would have to change them from bigint to varchar, etc. The data has 38 columns and around 50 mill rows per file so figuring out which categorical variables are strings or integers is a real pain. At the moment I am using: cur.copy_expert(sql="COPY %s FROM stdin DELIMITERS '~' CSV;", file=f), **with my data-type mainly being varchar**. I did this because the CSV is a bit messy and sometimes what I think is an integer turns out be alphanumeric and I have to re-upload. Would it be much slower to import as a Pandas data-frame (so that panda takes care of column-type for me) and use that with sqlachemy to insert into Postgres? I'm guessing if PANDAs is a bit slower it will make up for it because the column types will be optimised (since it will decide on that for me). E.g. something like this: import pandas as pd df = pd.read_csv('mypath.csv') from sqlalchemy import create_engine engine = create_engine('postgresql://username:password@localhost:5432/dbname') df.to_sql("table", engine) My main goal is to optimise this for the group-by command. **Second Edit:** Ahh, I guess best thing is to upload one CSV file using PANDAS and then copy the table structure into a new table which is then filled with the faster COPY command?
Ilia (133 rep)
Oct 5, 2015, 10:59 AM • Last activity: Apr 21, 2025, 08:22 PM
0 votes
2 answers
4992 views
MongoDB CSV Export: One Array/Column & Array Index on rows, or vice versa
I have a MongoDB schema that looks like this: const batchSchema = mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, time: {type: [Number]}, tmp: {type: [Number]}, hum: {type: [Number]}, co2: {type: [Number]}, coolRelay: {type: [Boolean]}, humRelay: {type: [Boolean]}, fanRelay: {type: [Boolean]}...
I have a MongoDB schema that looks like this: const batchSchema = mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, time: {type: [Number]}, tmp: {type: [Number]}, hum: {type: [Number]}, co2: {type: [Number]}, coolRelay: {type: [Boolean]}, humRelay: {type: [Boolean]}, fanRelay: {type: [Boolean]}, lightRelay: {type: [Boolean]}, }); My goal is to have a csv file I can import to excel for use in creating charts, graphs, and other visuals based on the data. Using Studio 3T(https://robomongo.org/) , this doesn't seem to be possible unless I'm just not understanding the settings. Doesn't really matter if the data is organized horizontally or vertically. As long as each is on it own column/row, excluding the _id field. 3T seems to be only capable of placing them all along the same row. I just tried using mongo's native cli csv export tool but found that didn't seem to come with my release. I'm running version 3.6 on openSuse, arm64, on a raspberry pi. mongoexport as a command was not found, and when I ran the suggested cnf mongoexport to find a package containing it, nothing was returned either. I know that I can export one file, per array using 3T, then cut/paste them together, however I hadn't planned on paying the annual license for 3T and was only using the free trial to get a more usable gui while in development. Was hoping to be able to write predefined bash script that could be reused repeatedly to export each "batch" document as it was completed. Is there something I am missing about mongoexport or is this a limitation of the aarch64 release? I really don't want to have to go back, learn, and re-write everything for postgreSQL at this point. I mean, I will if I have to, but wanted to check in with you all first.
AustinFoss (119 rep)
Mar 31, 2019, 03:00 AM • Last activity: Apr 18, 2025, 09:00 AM
-2 votes
1 answers
117 views
How to quickly load a large amount of data from a CSV file and write it to a database?
**Product name** >OceanBase V4.2.5-Community version **Problem description** >obd deployment cluster: >three machines 1-1-1, 16c64G, memory_limit=32G >Import csv file, 100 million data, 100 partitions by time field, no primary key set >I use this method to import data: >**load data/*+ parallel(9) lo...
**Product name** >OceanBase V4.2.5-Community version **Problem description** >obd deployment cluster: >three machines 1-1-1, 16c64G, memory_limit=32G >Import csv file, 100 million data, 100 partitions by time field, no primary key set >I use this method to import data: >**load data/*+ parallel(9) load_batch_size(18)*/** **The result is very time-consuming** How to deal with it to quickly import 100 million data? --- **System built-in tenant settings:**
alter system set system_memory=‘15g’; 
alter resource unit sys_unit_config max_memory=‘15g’,min_memory=‘15g’; 
#Tuning Parameters 
alter system set enable_merge_by_turn= False; 
alter system set trace_log_slow_query_watermark=‘100s’; 
alter system set max_kept_major_version_number=1; 
alter system set enable_sql_operator_dump=True; 
alter system set _hash_area_size=‘3g’; 
alter system set memstore_limit_percentage=50; 
alter system set enable_rebalance=False; 
alter system set memory_chunk_cache_size=‘1g’; 
alter system set minor_freeze_times=5; 
alter system set merge_thread_count=20; 
alter system set cache_wash_threshold=‘30g’; 
alter system set _ob_enable_prepared_statement=true; 
##Adjust the log level and number of saved logs 
alter system set syslog_level=‘PERF’; 
alter system set max_syslog_file_count=100; 
alter system set enable_syslog_recycle=‘True’;
**Customize tenant settings:**
CREATE RESOURCE UNIT unit1 max_cpu = 9,max_memory = 3006477108,min_memory = 3006477108, max_iops = 10000,min_iops = 1280,max_session_num = 3000,max_disk_size = 214748364800 – 200 GB; 
set global NLS_DATE_FORMAT=‘YYYY-MM-DD HH24:MI:SS’; 
set global NLS_TIMESTAMP_FORMAT=‘YYYY-MM-DD HH24:MI:SS.FF’; 
set global NLS_TIMESTAMP_TZ_FORMAT=‘YYYY-MM-DD HH24:MI:SS.FF TZR TZD’; 
set global ob_sql_work_area_percentage=80; 
set global optimizer_use_sql_plan_baselines = true; 
set global optimizer_capture_sql_plan_baselines = true; 
alter system set ob_enable_batched_multi_statement=‘true’; 
##Set under the tenant to prevent transaction timeout
show variables like ‘%timeout%’; 
set global ob_query_timeout=72000000000; 
set global ob_trx_timeout=72000000000; 
set global max_allowed_packet=67108864; 
#Execute load data permission
set global secure_file_priv=’’; 
grant file on *.* to sqluser01;
KooMaraLaHam (1 rep)
Apr 17, 2025, 03:19 AM • Last activity: Apr 17, 2025, 09:41 AM
0 votes
0 answers
17 views
Issue with local data upload into MySQL Server
Greetings to all users from a newcomer to this platform. I am facing the following situation: - I have successfully installed MySQL Server 8.0 & MySQL Workbench on my work computer (which is of course managed by my employer company and hence local admin privileges were required for the installation)...
Greetings to all users from a newcomer to this platform. I am facing the following situation: - I have successfully installed MySQL Server 8.0 & MySQL Workbench on my work computer (which is of course managed by my employer company and hence local admin privileges were required for the installation); for the time being my scope of use is quite limited and thus one and the same machine will both host the server and act as the client - I have also proceeded to create my first database together with an initial table, which is currently empty; so far everything went smooth - the problem appeared though upon attempting to run LOAD DATA INFILE in order to upload a locally prepared csv file in the above-mentioned table: running the LOAD DATA script produces the following: Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement. - Inspecting the secure-file-priv variable revealed however that I had placed the respective csv file in the *correct* place - the path to the dedicated upload folder specified by this variable - and *I have also made sure* that I am referencing this correct path in the LOAD DATA script. Nevertheless, the script will not execute: it appears as though for some reason the Server is oblivious of the actual location of the csv file and raises an error it should not! I suspect this has a great deal to do with the fact that the computer is company managed and perhaps the server has insufficient local folder access privileges (?!). If anyone of the more experienced users has encountered similar situations and could enlighten me on how to solve the above issue, I would be very grateful. Thank you for your time!
ΑΘΩ (101 rep)
Apr 16, 2025, 12:50 PM
2 votes
2 answers
9152 views
Load csv file to mysql using load data local infile
I need a simple way to load a csv file from my computer to the database (which is on a remote server). I'm trying to load the file using a php page that executes this code: ```php $file = $_FILES['csv']['tmp_name']; $handle = fopen($file,"r"); $name = $_FILES['csv']['name']; $import = "LOAD DATA LOC...
I need a simple way to load a csv file from my computer to the database (which is on a remote server). I'm trying to load the file using a php page that executes this code:
$file = $_FILES['csv']['tmp_name']; 
    $handle = fopen($file,"r"); 
    $name = $_FILES['csv']['name'];

   $import = "LOAD DATA LOCAL INFILE '" . $name .
                "' INTO TABLE temporal_load
                  FIELDS TERMINATED BY ','  
                  optionally ENCLOSED BY '\"' 
                  LINES TERMINATED BY '\\n' 
				  IGNORE 1 LINES
                  (num,ticker,company,sector,industry) ";

mysql_query($import) or die(mysql_error());
But when I select a file on the php page and try to load it, shows the error message: File 'test11-14-15.csv' not found (Errcode: 2) I already reviewed that the variable **mysql.allow_local_infile** is ON and the database connection was made this way:
mysql_connect(HOST,USER,PASSWORD,false,128);
The file is not on the remote server, the file is on my computer, but it should work anyway because I'm using LOCAL. What am I doing wrong???
Claudia Sanchez (21 rep)
Nov 23, 2015, 07:04 PM • Last activity: Apr 11, 2025, 03:04 AM
1 votes
2 answers
947 views
csv import fails without throwing an error
Ι am trying to import a csv file into an existing `mysql 5.7` table. Here is the command (the db is in docker with bind mount for persistence) mysql -h 127.0.0.1 -uroot -prootpass --local_infile=1 jira_statistics -e "LOAD DATA LOCAL INFILE '/home/centos/bugs.csv' INTO TABLE bugs FIELDS TERMINATED BY...
Ι am trying to import a csv file into an existing mysql 5.7 table. Here is the command (the db is in docker with bind mount for persistence) mysql -h 127.0.0.1 -uroot -prootpass --local_infile=1 jira_statistics -e "LOAD DATA LOCAL INFILE '/home/centos/bugs.csv' INTO TABLE bugs FIELDS TERMINATED BY ','" However: mysql> select * from bugs; Empty set (0.05 sec) The file cannot be loaded because there is a foreign key constraint. I need to be able to catch errors like this (and any others that might occur) as an exit code since I will be scripting a large number of imports like this. There is no error returned to the command line, and the docker logs of the MySQL container show no errors. What is more, the exit code of the mysql command is 0! Any ideas?
pkaramol (213 rep)
Feb 14, 2019, 02:12 PM • Last activity: Feb 18, 2025, 09:01 PM
0 votes
1 answers
199 views
Import CSV to Oracle Script DB
I managed to export data from a table in an Oracle database in .csv format using SQL Plus. I have this file locally. Now I need to import this same .csv file into another table in another Oracle database. The version of Oracle here at work is 11.2 and does not have the SQL Loader utility. What can I...
I managed to export data from a table in an Oracle database in .csv format using SQL Plus. I have this file locally. Now I need to import this same .csv file into another table in another Oracle database. The version of Oracle here at work is 11.2 and does not have the SQL Loader utility. What can I use to perform this import? I thought about creating a script that has a truncate and a code to take line by line from the CSV file and insert it into the database. How do I do this? Thank you
Joyce Ferreira (13 rep)
Dec 19, 2024, 04:42 PM • Last activity: Dec 20, 2024, 12:32 PM
Showing page 1 of 20 total questions