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
1answer
10 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 ...
1
vote
1answer
28 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
26 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
21 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
30 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
95 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
0answers
42 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
29 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
72 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
31 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
72 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
20 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
72 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
74 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
18 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
23 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
76 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
73 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
24 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
48 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
27 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
30 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
55 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
46 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
48 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
42 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
66 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
27 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
51 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
92 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
90 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
38 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 ...
0
votes
0answers
17 views

PostgreSQL rule to delete record before insertion, if the record has changed

I'm not sure it's possible to do this with a rule, but what I want to do is, when you insert a record: If it doesn't exist, just insert it as usual. If it exists, but each field is equal to what you'...
0
votes
1answer
101 views

INSERT .. ON CONFLICT DO UPDATE SET error

When I use the following query : cur.execute("""INSERT INTO TABLE (SELECT ID_tmp,First_seen_tmp,Last_seen_tmp,Duration_tmp FROM tmp_table) ON CONFLICT (ID) DO UPDATE SET Last_seen=...
3
votes
3answers
191 views

(Deadlock) Select Query Causes Insert Query to be Blocking in Transaction

Database: MySQL I have a running app with concurrency transactions in it. I noticed that there are so many errors occur related to deadlock. The error says SQLSTATE[40001]: Serialization failure: 1213 ...
6
votes
2answers
3k views

Why is “INSERT INTO table;” a syntax error?

I have this: CREATE TABLE people ( id bigserial, timestamp timestamptz DEFAULT now() NOT NULL, PRIMARY KEY (id) ); CREATE TABLE "...
0
votes
1answer
20 views

SQLite constraint violation - How to insert data to this schema?

First of all, sorry for the question but I was hours searching for a solution and the only things that I got are Java exceptions. I'm developing a little web crawler for movies, so I created this two ...
0
votes
0answers
28 views

insert or update with summary subquery

i have a problem with follwing query INSERT IGNORE INTO cartellino_anno (iddipendente, mese, ordinarie,effettive,assenze,straordinari,ritardo,anticipo,richiestaassenza,richiestastraordinario,...
0
votes
1answer
36 views

Is it possible to make a trigger that does not allow INSERT?

I'm currently learning how to implement sqlite commands through C code and I've been trying to figure out the best way to ensure that no data can be inserted to a table (which will only happen during ...
1
vote
2answers
226 views

How can I use LOAD DATA LOCAL INFILE for specific columns?

I have a directory of text files, as the filename is the id, and the content text for this table: CREATE TABLE texts ( ID int(11) unsigned, Added date, Text MEDIUMTEXT, PRIMARY KEY(ID) ) ENGINE=InnoDB ...
0
votes
1answer
35 views

MySQL: After inserting data into a table, the table remains empty

i'm trying to run this simple query: insert into diff_set_values(value) select value from diff_sets group by value; but after it is finished, there is no data in the destination table ...
0
votes
2answers
42 views

What is wrong with this mysql INSERT statement?

I have table: Book: - id:(int) primary key, autoincrement, not null, - title:(varchar) not null, - price: (decimal) not null and Artical: - id:(int) primary key, autoincrement, not null, - title:(...
0
votes
0answers
29 views

SQL Trigger fails retrieve new record in second query

Any advice on this will be appreciated This script created a table with new records. My script is failing to assign the "Inserted" ID to the query but manually assigning a value works (a) ...
0
votes
2answers
51 views

How to insert records using select statement?

Hi I am working on one project, here what I am trying is, I want to insert records what I get using select statements into temp table. but it is giving error to me, can any one help me to solve this ? ...
0
votes
1answer
28 views

How to prevent different connections treating bytea in same query differently?

I find that identical postgresql queries issued by two different clients are handled differently. Specifically, bytea values are inserted differently. A query that demonstrated the behaviour is this: ...

1
2 3 4 5
14