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
45 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
0answers
13 views

Populating a Junction Table in sqlite

Im a beginner in sqlite and I want to use sqlite in a database where I have three tables one as a junction table for the two tables. The two tables are named users and stocks table. I know that the ...
0
votes
1answer
49 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
19 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
49 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
17 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
148 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
8 views

How to prevent inconsistent OperationalError in pyodbc? [migrated]

Environment: OS: Windows (linux Docker container in the future after deployment) python 3.9, SQLAlchemy 1.4.19, pyodbc 4.0.30 Im using SQL Alchemy python module to communicate to Azure SQL. Workflow ...
1
vote
0answers
24 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
70 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
97 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
17 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
62 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
22 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
57 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
126 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
33 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
30 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
2answers
45 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
142 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
16 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
368 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
84 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
474 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
368 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
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
25 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
31 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
24 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
87 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
103 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
270 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
49 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
138 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
83 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 ...
1
vote
1answer
822 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
45 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
2 3 4 5
15