Questions tagged [insert]

Insert is an action to add information to a larger container that the information should reside within. Some examples include inserting a file into a file system, inserting a record into a database, or inserting an item into a list.

Insert is an action to add information to a larger container that the information should reside within. Some examples include inserting a file into a file system, inserting a row into a database, inserting an item into a list.

In programming languages, in the context of insertion of an item into a container (eg. arrays, linked lists), insert is normally used to denote addition of an item at an arbitrary point (by order of items) in the container. This is as opposed to append (add to end of container), or prepend (add to the front of the container).

Do not use this tag for questions regarding SQL INSERT statement. Use tag instead.

See also ,

14336 questions
284
votes
12 answers

Export specific rows from a PostgreSQL table as INSERT SQL script

I have a database schema named: nyummy and a table named cimory: create table nyummy.cimory ( id numeric(10,0) not null, name character varying(60) not null, city character varying(50) not null, CONSTRAINT cimory_pkey PRIMARY KEY (id) ); I…
null
  • 8,669
  • 16
  • 68
  • 98
230
votes
8 answers

Escaping single quote in PHP when inserting into MySQL

I have a perplexing issue that I can't seem to comprehend... I have two SQL statements: The first enters information from a form into the database. The second takes data from the database entered above, sends an email, and then logs the details of…
sjw
  • 2,603
  • 5
  • 22
  • 20
226
votes
2 answers

Insert at first position of a list in Python

How can I insert an element at the first index of a list? If I use list.insert(0, elem), does elem modify the content of the first index? Or do I have to create a new list with the first elem and then copy the old list inside this new one?
Fr0z3n7
  • 2,548
  • 2
  • 14
  • 15
224
votes
18 answers

Insert a row to pandas dataframe

I have a dataframe: s1 = pd.Series([5, 6, 7]) s2 = pd.Series([7, 8, 9]) df = pd.DataFrame([list(s1), list(s2)], columns = ["A", "B", "C"]) A B C 0 5 6 7 1 7 8 9 [2 rows x 3 columns] and I need to add a first row [2, 3, 4] to get: …
Meloun
  • 13,601
  • 17
  • 64
  • 93
221
votes
13 answers

Which is faster: multiple single INSERTs or one multiple-row INSERT?

I am trying to optimize one part of my code that inserts data into MySQL. Should I chain INSERTs to make one huge multiple-row INSERT or are multiple separate INSERTs faster?
dusoft
  • 11,289
  • 5
  • 38
  • 44
211
votes
13 answers

In STL maps, is it better to use map::insert than []?

A while ago, I had a discussion with a colleague about how to insert values in STL maps. I preferred map[key] = value; because it feels natural and is clear to read whereas he preferred map.insert(std::make_pair(key, value)). I just asked him and…
danio
  • 8,548
  • 6
  • 47
  • 55
207
votes
6 answers

How to do a batch insert in MySQL

I have 1-many number of records that need to be entered into a table. What is the best way to do this in a query? Should I just make a loop and insert one record per iteration? Or is there a better way?
Genadinik
  • 18,153
  • 63
  • 185
  • 284
204
votes
4 answers

Combining INSERT INTO and WITH/CTE

I have a very complex CTE and I would like to insert the result into a physical table. Is the following valid? INSERT INTO dbo.prf_BatchItemAdditionalAPartyNos ( BatchID, AccountNo, APartyNo, SourceRowID ) WITH tab ( --…
dcpartners
  • 5,176
  • 13
  • 50
  • 73
196
votes
13 answers

How to insert a row in an HTML table body in JavaScript

I have an HTML table with a header and a footer: …
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
191
votes
8 answers

postgresql: INSERT INTO ... (SELECT * ...)

I'm not sure if its standard SQL: INSERT INTO tblA (SELECT id, time FROM tblB WHERE time > 1000) What I'm looking for is: what if tblA and tblB are in different DB Servers. Does PostgreSql gives any utility or has any functionality…
Mayank
  • 5,454
  • 9
  • 37
  • 60
184
votes
11 answers

SQL Server: Is it possible to insert into two tables at the same time?

My database contains three tables called Object_Table, Data_Table and Link_Table. The link table just contains two columns, the identity of an object record and an identity of a data record. I want to copy the data from DATA_TABLE where it is linked…
tpower
  • 56,100
  • 19
  • 68
  • 100
182
votes
5 answers

Increment a database field by 1

With MySQL, if I have a field, of say logins, how would I go about updating that field by 1 within a sql command? I'm trying to create an INSERT query, that creates firstName, lastName and logins. However if the combination of firstName and…
Matt
  • 4,140
  • 9
  • 40
  • 64
180
votes
14 answers

LAST_INSERT_ID() MySQL

I have a MySQL question that I think must be quite easy. I need to return the LAST INSERTED ID from table1 when I run the following MySql query: INSERT INTO table1 (title,userid) VALUES ('test',1); INSERT INTO table2 (parentid,otherid,userid)…
Martin
  • 2,163
  • 6
  • 21
  • 16
179
votes
5 answers

Add new row to dataframe, at specific row-index, not appended?

The following code combines a vector with a dataframe: newrow = c(1:4) existingDF = rbind(existingDF,newrow) However this code always inserts the new row at the end of the dataframe. How can I insert the row at a specified point within the…
luciano
  • 13,158
  • 36
  • 90
  • 130
178
votes
6 answers

How to including variables within strings?

So, we all should know that you can include variables into strings by doing: String string = "A string " + aVariable; Is there a way to do it like: String string = "A string {aVariable}"; In other words: Without having to close the quotation marks…
Gray Adams
  • 3,927
  • 8
  • 32
  • 39
My Header
aaaaa