Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
-2 votes
0 answers
34 views

the SQL Server Database Engine cannot obtain a LOCK resource [closed]

I have a problem with the configuration of SQL Server I. I have SQL Server 2019 with the last cumulative update. I fixed the max server memory with 40000 Mo = 40 Go and maxdop to 0 lock, lock 0 i. I ...
ahmed.yeddes's user avatar
0 votes
1 answer
24 views

How to have Postgres return id when ON CONFLICT DO NOTHING

Suppose we have the following table: CREATE TABLE names( id SERIAL NOT NULL, CONSTRAINT names__pk PRIMARY KEY(id), name TEXT NOT NULL, CONSTRAINT names__name__unq UNIQUE(name) ); INSERT INTO names(...
user14381362's user avatar
1 vote
3 answers
85 views

Decreasing execution time of insert and deletes in SQL Server

I'm looking for some advice on reducing the execution time for inserts and deletes on a custom database setup that is used for logging data from a remote location. Basically I have a custom program ...
Big Bill's user avatar
3 votes
1 answer
391 views

"#1292 - Incorrect datetime value" when time is within one hour

I'm running into a bizarre error with a timestamp column in a MySQL DB. When inserting the date/time value, it fails with a #1292 error if the time is between 02:00:00 and 02:59:59. Here is a sample ...
lcdservices's user avatar
1 vote
1 answer
73 views

mysql bulk insert with constraints

I created a table like this, CREATE TABLE Leaderboard( userId bigint not null, matchId bigint not null, score mediumint not null, country CHAR(10), tournamentId int not null ) ...
umarkaa's user avatar
  • 37
0 votes
2 answers
24 views

(PostgreSQL) Insert a tuple containing specific value in a column linked to a sequence

I started writing this post as a question but, while reproducing the error, I found the solution in the PostgreSQL documentation. So I'll share the solution here for the community. A PostgreSQL 14 ...
ValerioOliveira's user avatar
0 votes
0 answers
65 views

How to get last executed statement on a particular table in Oracle?

Trying to identify what ghost process is inserting records into a particular table. Is there a way to get the exact query?
Dhaval Mohandas's user avatar
-2 votes
2 answers
64 views

Replace "INSERT" by "UPDATE"

I'm working with some tables in an SQL-Server database, and I'm doing some crucial modifications. In order not to loose everything when I mess up, I decided to do a "Generate script" (data ...
Dominique's user avatar
  • 521
1 vote
1 answer
39 views

Moving records between tables in CockroachDB is taking too long

I have a requirement where I have to move records from table original_table to table new_table for the last N days. Below is a small sample of my basic script that does this. while True: result = ...
Brunaldo's user avatar
0 votes
0 answers
58 views

How to insert data into temporary table from the table having encrypted columns in sql server

I am trying to insert data into a temporary table(#table1) from the table(table2) having encrypted column in it. I am getting below error while trying to insert data into temporary table from the ...
Prathap r's user avatar
0 votes
1 answer
205 views

question about using Insert where not exists instead of if not exists then

I have a procedure that insert data to table where the data doesn't exists. right now it's done in two steps : check if the data exists already, if not, insert it i want to change it to do INSERT ...
dexon's user avatar
  • 47
0 votes
2 answers
93 views

SQL Server inserts fails silently

I have a stored procedure that inserts some rows into a table. Sometimes it seems to fail (can't find the new records) although I know the statements did execute. The code I use is bellow. After ...
Eyal Hasson's user avatar
0 votes
1 answer
52 views

Move row of a table to an inherited table in PostgreSQL

I have tables created as such: BEGIN; CREATE TABLE tag ( id SERIAL, name VARCHAR(255) UNIQUE NOT NULL, description VARCHAR(511) NOT NULL DEFAULT '', PRIMARY KEY(id) )...
SK19's user avatar
  • 101
0 votes
0 answers
62 views

Mariadb Triggers after multiple insert, update one table one one time

CREATE TRIGGER after_composers_insert AFTER INSERT ON composers FOR EACH ROW UPDATE listings SET composer_name = NEW.composer_name WHERE composer_id = NEW.composer_id; CREATE TRIGGER ...
Alain Lagune's user avatar
-1 votes
2 answers
64 views

SQL breaking my query where there is NULL value

Here is my sql statement and the error I am facing: SQL> INSERT INTO COUNTRY(COUNTRY_CODE) select unique(country_code) from AIRPORTDEMODATA where country_code IS NOT NULL; 2 INSERT INTO COUNTRY(...
Java_Beginner's user avatar
0 votes
1 answer
35 views

Is commit of first insert necessary if second insert has constraint depedent on first insert?

Using MariaDB I am running an insert on one table and then trying to run another insert on second table. Due to a constraint the second insert should only succeed if the first one was successful. If I ...
loris's user avatar
  • 103
0 votes
1 answer
213 views

Auto-increment [id] field in a table in an SQL-Server database

I have different tables, containing an id field. That field is typically defined as id (PK, int, not null). Normally, when adding an entry to a table, I add the value of the id field myself, but I'm ...
Dominique's user avatar
  • 521
0 votes
1 answer
148 views

In PostgreSQL, what is the `index_predicate` for in `INSERT`?

The docs on INSERT say: If an index_predicate is specified, it must, as a further requirement for inference, satisfy arbiter indexes. Note that this means a non-partial unique index (a unique index ...
Nathan Long's user avatar
1 vote
1 answer
143 views

Lazily Evaluate Insert Arguments If Constraint Violated

create table a ( b text not null unique, c text not null ); -- Sleeps for 1 second as expected. insert into a (b, c) values ('d', pg_sleep(1)); -- Sleeps for 1 second even though record is ...
Mario Ishac's user avatar
0 votes
1 answer
33 views

Delete records from table that are not in the file being inserted

I have a Snaplogic pipeline that queries a web application every night and loads the data into a SQL Server table. I use the 'Update' snap to add new records or add any changes. The goal is that the ...
Matt's user avatar
  • 271
1 vote
1 answer
404 views

How to handle deadlocks while multiple batch inserts?

I need suggestions/ideas of handling a issue with deadlocks. I'm having multiple batch inserts commands to same table: insert into ip (id, p_id, m_type, m_id, sha256, path) VALUES ($1, $2, $3, $4, $5, ...
KaliTheGreat's user avatar
1 vote
1 answer
91 views

insert trigger to auto-set key fields for composite primary key

Basically the next step for Error "UNIQUE constraint failed" with composite primary key: I created a trigger after insert to set SEQ to the highest SEQ plus one if it's less than one. ...
U. Windl's user avatar
  • 125
1 vote
1 answer
151 views

SQL Server stored proc locking, serialization

Stored proc in SQL Server INSERT INTO table1 value sets A , B Value set A has as one of its parameters: (SELECT TOP 1 cashbalance - 1 FROM table1 WHERE userid = __ ORDER BY createdUTC, ID) Value set B ...
M S's user avatar
  • 21
1 vote
0 answers
152 views

Copy rows and change corresponding values

I have 4 tables Tables are used to store product attributes and its values in different languages I'm trying to copy attribute (copy in same table to new row and increment/change some values). First ...
Webzber's user avatar
  • 11
0 votes
1 answer
270 views

What is the most straightforward way to create subtypes and supertypes at the same time?

I hope this isn't too basic a question, but I am hoping that the DB engineers here will help me out. Do relational DBs usually have a straightforward way of doing the following?: Create a supertable ...
Logos Masters's user avatar
0 votes
1 answer
214 views

MSSQL - Insert Into Select number from global count table and update the global count for each row then inserted

Not sure I've articulated that well in the title, so here goes... I have three tables Table1 ID NewNames 10 some row data 11 some more row data Table2 ID OldNames 1 my old data 2 and more data ...
Les's user avatar
  • 1
0 votes
1 answer
43 views

Compositing ordered SQL tables without Joins

I'm currently exploring some weird ways of doing things and was wondering if anyone has any experience with the following methodology. Background I have a handful of NF3 tables, and NF1 source data. ...
Vocoder's user avatar
  • 117
0 votes
1 answer
96 views

Migrate columns from table A to table B, and update A with a reference to B

I have a table A with some columns that need to be migrated to a new table B. But I also need to create a column in table A to reference the id's from the new columns in the table B. I've tried doing ...
Warix3's user avatar
  • 1
0 votes
1 answer
272 views

SQL Server: Inserting empty value (zero-arity INSERT) [duplicate]

I made test table: create table tmp (id BIGINT NOT NULL IDENTITY PRIMARY KEY) Now I want to insert a value: insert into tmp () values(); and it complains: SQL Error [102] [S0001]: Incorrect syntax ...
gavenkoa's user avatar
  • 509
0 votes
1 answer
78 views

MySQL gives Unknown column error when forward engineering database from diagram

I have a MySQL EER diagram the I forward engineer into a database. I also use the forward engineer feature to generate insert statements for data automatically. After entering about 120 rows of data I ...
SlowlySwift's user avatar
2 votes
1 answer
61 views

Inefficiency of index in SELECT requests after large INSERT requests on myisam tables on MariaDB 10.6

This is my first post on this website. Please don’t hesitate to indicate me if there is any problem in my post. I have a new issue when migrating from MariaDB 10.1 to MariaDB 10.6 on indexes with ...
Tom Tom's user avatar
  • 21
0 votes
0 answers
101 views

Problem with inserting a new row - unknown column name reported missing

I'm new to SQL Anywhere. I have a SQL Anywhere 11 database that was not designed by me. I'm trying to insert a new row in a table with let's say 3 columns. When I execute the sql statement insert into ...
user2274824's user avatar
0 votes
1 answer
724 views

Insert rows into a (postgres) table where the first col is a static value and the second col is the result of a SELECT DISTINCT from another table

I haven't had to use SQL in years and I'm clearly rusty. I have a situation where I'm trying to insert multiple rows into table A. There are two columns of data to be inserted, the first is a "...
Amy Lee's user avatar
0 votes
0 answers
51 views

How do I automatically insert a row into parent table when a row is created in a child table?

I am working on a MySQL database that has to treat organizations and people as interchangeable in some instances and not others. Because of this, I created a table called LegalEntity as a superclass. ...
SlowlySwift's user avatar
2 votes
2 answers
1k views

PostgreSQL: Insert dynamic columns and values from jsonb argument

This question relates to Update dynamic column names using keys from jsonb argument and my code is based on the answer provided there by https://dba.stackexchange.com/users/3684/erwin-brandstetter I'm ...
Russell Turner's user avatar
0 votes
1 answer
1k views

SET BIGINT fieldname value to 0 automatically if inserting empty string

How do I do something like : INSERT INTO tablename SET customer_id = '' WHERE <condition>; customer_id is BIGINT NULL Default NULL But when I execute SET customer_id = '' it gives Incorrect ...
anjanesh's user avatar
  • 279
1 vote
2 answers
1k views

How can I insert into a Postgres table with a unique constraint without waiting on concurrent transactions?

I have a table like this in a Postgres database: CREATE TABLE tabwithunique ( id SERIAL PRIMARY KEY, key BIGINT NOT NULL UNIQUE, value BIGINT NOT NULL ); I want to design a statement that ...
Curtis Fenner's user avatar
1 vote
2 answers
284 views

MariaDB: Large INSERT SELECT query failed without generating an error

I have a large complicated neuroscience dataset that I am attempting to organize in a database for concurrent and consistent access with my lab. This is my first foray beyond much smaller experiments ...
Chris Cox's user avatar
1 vote
2 answers
897 views

Insert values and add values to foreign key

I have two tables: CREATE TABLE est ( est_id serial PRIMARY KEY , est_nom varchar(70) ); CREATE TABLE bm ( id serial PRIMARY KEY , est_nom int , nom varchar(70) , CONSTRAINT FK_bm_est FOREIGN KEY(...
David Palacios's user avatar
1 vote
2 answers
237 views

Is it safe to use lastval/currval for multiple inserts?

Lets say I have those tables: CREATE TABLE buildings ( id_building serial4 NOT NULL, street text NULL, CONSTRAINT buildings_pkey PRIMARY KEY (id_building) ); CREATE TABLE families ( ...
Sotis's user avatar
  • 306
0 votes
1 answer
122 views

Insert Statement on large MySQL table does not terminate

I have a MySQL database with several tables. One table (InnoDB) is quite large (about 490 million rows). The table consists of 4 columns: id: int(11), auto_increment term: varchar(255) docId: int(11) ...
Philipp's user avatar
-1 votes
1 answer
5k views

Stored procedure to Insert data into table with select statement and argument parameter [duplicate]

I am creating a stored procedure which will populate my table with data passed from procedure argument and from other table. I have a table with three columns (cart_id, product, sold_quantity). Now, I ...
Jaimin Sutariya's user avatar
0 votes
2 answers
801 views

PostgreSQL, INSERT INTO SELECT DISTINCT generates more rows?

I have a large PostgreSQL table (NOT indexed) with duplicates so I ran the following query to eventually end up with a unique rows table: INSERT INTO newTable(Field1, Field2, Field3) SELECT DISTINCT ...
Anvil's user avatar
  • 11
3 votes
3 answers
1k views

MySQL: How to make Trigger to insert row in another table?

Please read everything, included the notes and edits at the end Problem I have a MySQL DB with 3 different table: To save users mysql> describe users; +-------------+-----------------------------...
Cromega08's user avatar
1 vote
0 answers
219 views

update trigger after insert on same table

So, I'm supposed to make a trigger that applies md5 to a row after an INSERT was made on it. Here is what I came up with: delimiter $$\ create trigger pd_encrip before insert on usuario\ for each row\ ...
Jade Fernandes's user avatar
1 vote
0 answers
157 views

PL SQL code that Inserts data from a different table and gives new id values from the same table that the data is being inserted

What could I change to make this insert work and give a new ID value on each row I am inserting? Right now it's giving all the inserted rows the same ID number. Sadly, I can't use triggers and ...
Kristofers Kaprāns's user avatar
1 vote
0 answers
110 views

Auto Increment ID based on 2 columns

I have table called Logs. it has 4 columns ID, USER_ID, USER_TYPE, USER_ACTION where USER_ID is unique USER_TYPE is unique for every USER_ID and USER_ACTION can be anything 1,2,3 or A to Z. USER_ID ...
Zoheb Patel's user avatar
3 votes
1 answer
864 views

How To Optimize a Query That Aggregates Then Duplicates a Large Number of Records in a Single Table

In the following post, J.D. brings up that I have a poorly performing query. I am running this query on SQL Server 2019 Standard Edition (query plan was generated in Development Edition) Let's take a ...
David Rogers's user avatar
0 votes
2 answers
2k views

Postgresql: Trigger is not working at times

I have a PostgreSQL trigger that is not firing sometimes, even though the status is always shown as "enabled". My trigger code is as follows: CREATE OR REPLACE FUNCTION audit_src_exhibit() ...
Arun's user avatar
  • 13
0 votes
1 answer
426 views

Postgresql: Trigger is not working at times

I have a PostgreSQL trigger that is not firing sometimes, even though the status is always shown as "enabled". My trigger code is as follows: CREATE OR REPLACE FUNCTION audit_src_exhibit() ...
Arun's user avatar
  • 13

1
2 3 4 5
17