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
19 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
41 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
58 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
15 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
35 views

postgres: 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
81 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 ...
0
votes
1answer
44 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
282 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
23 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
22 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
17 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
30 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
30 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
22 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
43 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 ...
2
votes
1answer
101 views

how to use the keyword `VALUES` in an `IN` statement?

I am on sql server 2016 select @@version Microsoft SQL Server 2016 (SP2-CU15) (KB4577775) - 13.0.5850.14 (X64) Sep 17 2020 22:12:45 Copyright (c) Microsoft Corporation Enterprise Edition: Core-...
0
votes
2answers
21 views

Postgres: insert new row in table if the table does not have records where column_name = 'abc' occurs N times?

I would like to do this in one transaction So let's take table with columns: user -> [first_name, last_name] The use case is that we don't want to insert a new record into a table, if the table ...
0
votes
1answer
69 views

Insert/update loop ORACLE function

I want to find the best solution for an insert/update oracle function. My task is to collect some date from multiple tables (source tables) and bring them to a single table (destination table). Source ...
0
votes
3answers
35 views

setting a foreign key to an empty string

I'm trying to set a foreign key to an empty string but i keep getting this error. Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`msis230`.`deptchair`, CONSTRAINT ...
1
vote
1answer
90 views

Inserting Data using Cursor but check if the data already in the table

I want to check if data already exist in a table before I do an insert using a cursor. So the cursor will pick a record, check that record doesn't exist in the table. IF it Doesn't EXIST then Insert, ...
0
votes
0answers
60 views

Insert into junction table and one of the many-to-many tables

I have these two tables, exercises and workouts, each just for this example having only id and name and a junction table between them workout_exercises, since an exercise can belong to many exercises ...
0
votes
1answer
342 views

Postgresql INSERT stuck, what can cause this with no locks blocking

I had a weird issue with our analytical pipeline and i'm not sure exactly what I can provide for this situation. Essentially I had a 504 gateway timeout alert around 3am during one of our analytical ...
1
vote
2answers
32 views

SQLite3 'OR IGNORE' leaves empty primary key IDs

I use 'INSERT OR IGNORE INTO' in my main table which works fine but leaves empty primary key IDs when records are ignored. This leads to big jumps in my primary key numbering because I re-scan part of ...
1
vote
0answers
17 views

Analyzing performance of an insert int postgres

I have a statement which is inserting a bunch of rows (doesn't really matter what or where for this question) into a Postgres DB and it isn't as fast as I'd like. I can run an explain query to see ...
0
votes
2answers
184 views

Hint: There is a column named “pma_timestamp” in table “table_a”, but it cannot be referenced from this part of the query [closed]

I want to use a user defined function so that while inserting values in column i want to insert last_day of the month in one column by referencing other column in same table. my code is- insert into ...
0
votes
1answer
155 views

Prevent unique constraint violations caused by concurrent inserts

I have a situation where I need to insert a unique record into the database: SELECT user FROM users WHERE id = 'some_randomly_generated_id' If user does not exist, INSERT INTO users WHERE id = '...
0
votes
1answer
33 views

PostgreSQL update table then insert on another table

I have a User table and a Log table. I need to update a field on the User table and insert a new entry on the Log table recording the update. I have written the statement for the update: UPDATE ...
0
votes
3answers
27 views

Load data from a Table that has the same structure as Table1 with the only diferrence of an ID not null column?

So, I know that if you want to load data into a table that does not have the same structure as the data, well you have to do it in the way of column by column, the thing that in this situation, I have ...
0
votes
1answer
161 views

How to ensure no duplicate records are added when using multiple Node JS processes

We are working on an appointment scheduler. We have a table Appointment that stores an appointment with starttime, endtime, assigneeId and eventId. We are using Bookshelf.js as an ORM with Node JS. ...
0
votes
1answer
95 views

SQL CTE Expression with Cross Join - Can it be simplified?

I am looking to simplify the below SQL Query. Currently it's taking 44 mins to run. The main issue seems to be the WHERE [Versions] = (SELECT max([Versions]) from BPC_CTE) statement. What I'd like to ...
0
votes
1answer
25 views

MySQL Insert/Update across 3 tables with 1m+ rows

To start with, I know nothing of database design, so I apologise if this seems obvious to others. I have been researching up to 3NF over the last few weeks, and I think I have a layout that works. I ...
0
votes
1answer
56 views

“SQL command not properly ended” with trigger

Problem No matter what I do, I can not get my trigger to work. It seems to always complain about SQL command not properly ended, ignoring SQL statement and so on. Research I have spent hours looking ...
0
votes
2answers
38 views

Can we WITH x AS ( … ) INSERT INTO y(k) SELECT * FROM x in MySQL?

We can do INSERT INTO SELECT, but what if I have a bunch of WITH AS statements (about 27ish) for the SELECT part? My current solution is do the query then scan using programming language (Golang for ...
0
votes
0answers
47 views

Trigger to enforce unique constraint on text column (Geometry) to resolve INSERT conflicts

I have a simple table with a geometry column like so: CREATE TABLE geomtable ( gid serial, geom geometry, trip_count integer ); I want a unique constraint on the geometry column, such that ...
0
votes
1answer
57 views

Why can't I make this insert statement a procedure?

The insert statement works, but when I try to make it a procedure it doesn't compile. CREATE OR REPLACE PROCEDURE INSERT_INTO_CPP AS BEGIN INSERT INTO cpp /*+ ignore_row_on_dupkey_index ( cpp ( ...
0
votes
1answer
77 views

How do I close log files that are open in OracleServiceORCL after inputting data into Oracle?

I inserted data into a table called cell_local_stage1. With this procedure: CREATE TABLE cell_local_stage1 ( construct_id NUMBER(10), n_term VARCHAR2 (50), enz_name VARCHAR2 (50),...
0
votes
1answer
49 views

Problem Insert Data to connected tables postgresql

I have 2 existing tables: ‘projects’ and ‘units’.The two tables are connected through the project id. In the table 'projects' the column is called ‘id’ and generates every time a new project is ...
0
votes
1answer
25 views

Why am I getting ERROR: column “GLOBE-BE-154” does not exist

I create a Table in a Database and looks as following test1=# SELECT * FROM stunden_Plan; stunde | montag | dienstag | mittwoch | donnerstag | freitag --------+--------+----------+----------+--------...
0
votes
1answer
46 views

Is my theory on INSERT deadlocks correct?

I originally had this (as three separate PG queries, from my applications): INSERT INTO table1 (col1) VALUES ($1) ON CONFLICT DO NOTHING; INSERT INTO table2 (col1) VALUES ($1) ON CONFLICT DO NOTHING; ...
0
votes
0answers
84 views

How to insert variable number of rows inside an SQL Function with multiple queries?

My original idea was to use a transaction, since we have three statements and I want all or none. The transaction block looks something like below: BEGIN; INSERT INTO analysis_record (user_id,...
0
votes
2answers
53 views

how to insert big data in mariadb with execution time less than max_statement_time value

i have some table with this structure. CREATE TABLE `trcdmppdetail` ( `mpp_code` varchar(50) NOT NULL, `company_code` varchar(50) NOT NULL, `mppdetail_date` datetime(3) NOT NULL, `position_id` ...
0
votes
0answers
54 views

Making a trigger to update FK based on columns in another table and an external table

I'm inserting data into a database and I want the FKs to be populated automatically based on other information that links each FK to its corresponding PK. Here's my plan: Create an external table of ...
1
vote
1answer
135 views

Oracle: Inserting into table error - either duplicate column name or invalid datatype

I'm trying to insert data from an external table. INSERT /*+ ignore_row_on_dupkey_index ( consruct ( construct_id ) ) */ INTO construct (construct_id, n_term , enz_name, ...
0
votes
2answers
28 views

Transfer rows into a new table, forcing to generate unique primary keys till its insertable

Lets say we have the following scenario... +-----------------+-------------+---------------+ | Table | PK | Additional | +-----------------+-------------+---------------+ | ...
0
votes
1answer
102 views

Inserting into table: either invalid datatype or duplicate column name error. (But the datatype is valid and there's no duplicate) [duplicate]

Spoiler: solution to this is here. the solution was really simple. I'm trying to insert data from an external table. Here's the code I'm trying to use: INSERT /*+ ignore_row_on_dupkey_index ( consruct ...
0
votes
1answer
45 views

Why am i getting “missing right parenthesis” error when i try to LOG ERRORS when loading from an external table?

I've successfully created an error logging table BEGIN DBMS_ERRLOG.create_error_log( dml_table_name => 'enzyme', skip_unsupported => TRUE); END; / desc ERR$_ENZYME; Name ...

1
2 3 4 5
15