Questions tagged [insert]

A core statement in SQL that does what it says on the tin: inserts data into a table.

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

MariaDB veryslow Inserts Query/Import via Dbeaver

I have a MariaDB server that via DBeaver is getting very slows insert times. Tables with 10.000 lines only is getting imported in 2minutes The DB Manager is trying to import CSVs, some with only 80mb ...
3
votes
1answer
85 views

MySQL/MariaDB: can a SELECT query block an INSERT query?

Let's suppose that I have a query in the form: INSERT INTO tableA (...) select ... from tableB; Now, is it possible that this query, while executing, blocks plain INSERT statements to tableB? ...
0
votes
1answer
35 views

Why insert statements get slow when having too many indexes?

I am having a slowness in my insert statements when working with MongoDB, and when I did a quick investigation, I though this might happened because the table has 11 indexes. Plus, I know that when I ...
0
votes
0answers
16 views

Avoid duplicated insert in PostgreSQL [duplicate]

I'm struggling to handle concurrent insert in my table on PostgreSQL. I have the table monitoring_services with the following structure: create table monitoring_services( id integer default nextval('...
0
votes
1answer
26 views

MYSQL Error 1064 on INSERT INTO with CTE [closed]

I am trying to write a stored procedure to return a calculated value from a dataset by writing the result to a table. When I run this code on MySQL 8.0.32, I get an error 1064 Syntax error on the ...
0
votes
2answers
38 views

UPSERT unless the date is the same

There's a table CREATE TABLE IF NOT EXISTS table00 ( userid int8 PRIMARY KEY, save date NOT NULL, value int4 ); where I want to upsert values IFF the date is not the same ...
0
votes
1answer
59 views

INSERT a row at most once per day

I have a Postgres table which (for simplicity) looks like: CREATE TABLE IF NOT EXISTS tt_series ( i serial8 PRIMARY KEY, userid int8 NOT NULL, date int4 NOT NULL, followers ...
0
votes
1answer
31 views

Sybase ASE 15.7 procedure cache fail on INSERT

Sybase executes SELECT query with 50k rows in 10 seconds. If execute INSERT INTO ... SELECT ... FROM ... construction it executes 2 minutes But if we increase retrieved rows number in 2 times - 100k ...
1
vote
1answer
50 views

Insert values to table only if first Insert was successful

Is there a way I could check the status of an insert query whether it was successful or not. I want to write to another table only if the first insertion was successful. Below is the table I want to ...
0
votes
2answers
46 views

insert on table being unnaturally slow

I have an "Basic" pricing tier Azure SQL database with a table of 7 columns, an ID column of int that is the clustered index and primary key, one datetime2(0) column, 3 varchar(100) columns ...
0
votes
1answer
90 views

How to add a new row to a sql server table in the first position (from python) [duplicate]

I have an sql table Tab 1 in a Database. It is ordered in descent way based on the date. This table has to be updated with new records from python. In python I have another table Tab 2 similar to this ...
0
votes
1answer
78 views

Insert a FOR JSON result into a table column

I have the a result of a FOR JSON expression, and I'd like to insert it into a table column. How do I do that? Here is one of my unsuccessful trials (note that the SELECT hightrees ... FOR JSON PATH ...
-1
votes
2answers
36 views

INSERT VALUES TO A COLUMN WITH 2 FOREIGN KEY

I have tables "course" and "student" with n-n relationship,so I create another table name "course_student" to handle that. --Table course-- .id //primary ...
0
votes
2answers
22 views

Insert query in Orcale database - not showing the row in a table

I am inserting a row in the Oracle database table. The query looks like as below - INSERT INTO <schema_name>.<Table_name> (SID, LABEL, DESCR, GTI_EXPTYP, GTI_MODUS, GTI_NAME) VALUES (22, '...
0
votes
0answers
9 views

Can I version non-seed data scripts in SSDT project?

I have an SSDT project to version my DB schema. Now I'd like to add to it script files that insert/delete data for integration tests. These scripts are not post-deploy, they will be called before ...
0
votes
1answer
168 views

How to insert a row from JSON in Postgres

I have 2 tables recording company market data. A table recording stock market symbols CREATE TABLE appl.symbols ( id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, symbol VARCHAR(10) NOT NULL, ...
0
votes
0answers
25 views

How to transfer data from one table to another with exception handling in Postgresql?

So, I have two tables, one where I import data from an excel file all in string format without considering any sorts of constraints or data type validation. And then the data is transferred to the ...
2
votes
2answers
678 views

How to create a postgres function that returns a value

I am trying to move some of my web app logic into postgres functions. But I am hitting some errors while creating a very basic insert function. This is the function that I am trying to create; CREATE ...
1
vote
0answers
28 views

Postgresql stale result for insert into select

I've noticed when two processes (let's call them A and B) insert a record into the same table in Postgresql and don't commit those changes, the 2nd (later process, B) blocks until the 1st process (A) ...
0
votes
1answer
115 views

Insert into table with polymorphic association in database

I want to design a database where some tables have multiple foreign keys. I am looking for the best design approach. I found out that this kind of problem is called "polymorphic association" ...
1
vote
1answer
272 views

Constraint in ON CONFLICT clause has no associated index

I have this simple setup using PostgreSQL 13, latest dockerized: CREATE TABLE stop ( id INT UNIQUE, name TEXT, PRIMARY KEY(id) ); CREATE TABLE line ( id INT UNIQUE,...
1
vote
2answers
125 views

Missing an inserted row

I am having a strange heisenbug when a set of queries in a transaction (in MariaDB 10.2.38) somehow results in missing rows afterward. I mean that there are rows inserted within the transaction, but ...
0
votes
1answer
18 views

Adding new user info to current old user accounts

Hey all so I have a database that has been up and running for a few months now. I had a request to add the users First and Last name as well as their organization. This was easy enough to do for NEW ...
0
votes
2answers
278 views

Avoid duplicates in PostgreSQL among the rows that are going to be inserted

I have a destination table a and a set of source tables b and c. I'm trying to do an insert to a from b and c, and additionally check if such combination of (column1, column2) do not already exists in ...
0
votes
0answers
23 views

MySQL scheduled events not working on newly-added data

I can get a scheduled event to perform calculations on a current table. But it won't perform calculations on any new rows that are added to the table. How can I get the event to use the current ...
4
votes
1answer
75 views

INSERT duplicate rows for multiple, cascading 1:M child tables

Imagine multiple parent-child tables with 1:M relationships. I would like to "cascade"-insert duplicate rows based on root parent table row selection. Each table has IDENTITY primary key and ...
1
vote
2answers
256 views

ON DUPLICATE KEY UPDATE in INSERT INTO SELECT with GROUP BY

I have the query of INSERT IGNORE INTO t2 (ID,P1,P2,Items) SELECT ID,P1,P2,SUM(Items) FROM t1 GROUP BY ID,P1,P2; Since I need to run this query frequently to inspect changes in t1, I need ...
0
votes
1answer
37 views

Insert into table if column <> "Text" for each project

I have created two triggers to insert into fact table if a new row is inserted into dim table. One checks if Project exists already and if not, then query will be triggered and adds 12 new rows per ...
0
votes
1answer
33 views

Insert JSONL with two columns of comma separated fields into separate rows in mysql

I have json datas in the format as shown below. **the number of objects under 'images'(VIEWS, ROOMS, etc.) varied for each JSON object. Not all objects have VIEWS...POOL, it may only have ROOMS. &...
0
votes
1answer
50 views

Using Trigger creates duplicates

I have created a trigger to inert into table2 if a new row is inserted into table1 (at least I thought). The queries is like this: CREATE TRIGGER project_insert ON TABLE1 AFTER INSERT AS BEGIN Insert ...
0
votes
1answer
35 views

MS SQL Creating Tables and Adding Values by a Trigger

Table_A is an existing table which has 3 columns Id (PK), Name, Stock. I would like to create a trigger to create a table. For example, Table_A has an item, Id (PK) = 3, Name = Apple, Stock = 10. By ...
0
votes
0answers
22 views

Very slow query for massive stats calculation

In our app, we need to calculate the price comparison between a listing and its applicable comparables. It needs to happen for all active listings in DB on daily basis. The numbers of listings we are ...
0
votes
1answer
42 views

INSERT-ing to a table if the the data does not already exits - how do indexes peform in this scenario?

When you are in the position of inserting data into a table if the data does not already exist ...what is the best way to go with indexes? I'm specifically thinking of SQL Server here but I assume the ...
0
votes
0answers
23 views

Replace or Update a Table Row - based on the presence of a matching row item

Unfortunately I know next to nothing about php coding that contains some sql code. The examples I have seen online do not seem to match the same syntax that I inherited with this code, which is making ...
0
votes
2answers
227 views

MariaDB: Insert records (list of tuples) into table if not exists

Currently I have several sql queries that look like this: INSERT INTO `test` (col1, col2) SELECT * FROM (SELECT '1','2') AS tmp WHERE NOT EXISTS ( SELECT * FROM `test` WHERE col1='1' AND col2='...
1
vote
1answer
31 views

How to insert rows for each of the type column?

How to insert rows for each of the type column? If there is two type, type 1 and type 2, then I need to insert two rows and also need to change the order and id value for whole table. current status: ...
0
votes
0answers
19 views

Does MySQL have a built-in way to tell whether a view is insertable (not just updatable)? E.g., something like the IS_UPDATABLE flag, but for INSERT?

The MySQL documentation for the INFORMATION_SCHEMA.VIEWS table mentions that MySQL sets a flag whenever a view is created that records whether that view is updatable, i.e., whether you can UPDATE the ...
0
votes
1answer
24 views

Postgres handle case to continue Insert other row if some row doesn't exists

I am trying to insert data to a table using below query: INSERT INTO projects_users (user_id, project_id, is_admin) VALUES ( (Select id from users where username='example'), (...
0
votes
1answer
578 views

Insert multiple rows into a table with id from other table if not exists insert to other table

I have done similar task where I can insert a row into a table if data doesn't exists: WITH user_exists AS ( Select id from users where username='%s' ), user_new ...
0
votes
1answer
89 views

SQL Trigger to Insert a row in Table B is the record is inserted in Table A [closed]

I have a requirement where I have to Insert a Record into Table "Site" after the record is inserted into InventOperationalSiteStaging Table. I created a SQL trigger which is working fine for ...
-1
votes
1answer
764 views

insert data in multiple tables in one mysql query

Suppose there are two tables e1 and e2 with e1 |id |time | ca| cb| |1 | 12:20:00| 5 | 10| |2 | 12:25:00| 9 | 6 | and: e2 |id| time | cc| |1 | 12:20:00| 11| |2 | 12:25:00| 50| Now I ...
1
vote
2answers
451 views

MySQL stuck on INSERT INTO ... SELECT

I have a problem with my database. I have a production server running MySQL 5.5.33 and a local test server running MySQL 5.5.5. The only other difference I can think of is that the prod DB is being ...
-1
votes
1answer
24 views

Hello I want to create a before insert that looks if the value is on another table before inserting [closed]

I have a database for hospitals and I have a table for patients and one table for appointments. I need to create a trigger that if someone wants to add a person on the appointments table that person ...
0
votes
1answer
23 views

Insert INTO a table combining * with a column value

In MySQL, I am trying to insert all values from table A to table B, but I need to change the structure of table B and a column where all the values would be 0. Is it possible to mix and create such a ...
0
votes
1answer
50 views

Zabbix MariaDB Copy item data to another item

My current DB: MariaDB [zabbix]> SELECT VERSION(); +----------------------+ | VERSION() | +----------------------+ | 10.0.28-MariaDB-2+b1 | +----------------------+ There are some ...
0
votes
1answer
13 views

Two diferent time mysql databases with same uniqueid autoincrement values need to be merged

I am a beginner at SQL, so I will try to ask for help. As I have a database where is primary key where values are incremented by +1. And I made this database backup, and have another database same as ...
0
votes
1answer
33 views

Effectively saving a graph (terabytes) in a database

I'm new here so I'm not entirely sure what tags to use so please notify/edit if this should be changed, thanks! Background I have a graph with ~4 billion nodes and ~1 trillion edges that I want to ...
0
votes
1answer
34 views

Postgres SQL: INSERT from DELETE

I have a table with id,user_id,timestamp and I'm trying to INSERT into the table, the user_id from a DELETE from table where id=some_number and timestamp. So what I'm trying to achieve looks like: ...
0
votes
1answer
25 views

SQL insert which updates one table and based on a field value chooses what other table needs updating

DB setup: MSSQL I have a source record coming in via API call. That call is intended to update a system in the database. The first table is a common table where all systems have some details SystemId ...
0
votes
2answers
136 views

MySQL Insert Values Into Normalized Relational Database (multiple tables) at the same time

I have normalised my database to 4NF. How do I now insert values at the same time when records have been split into multiple tables? most of the child tables reference their parent table CUSTOMER ...

1
2 3 4 5
15