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
177
votes
24 answers

PDO Prepared Inserts multiple rows in single query

I am currently using this type of SQL on MySQL to insert multiple rows of values in one single query: INSERT INTO `tbl` (`key1`,`key2`) VALUES ('r1v1','r1v2'),('r2v1','r2v2'),... On the readings on PDO, the use prepared statements should give me a…
hoball
  • 3,146
  • 5
  • 23
  • 15
173
votes
6 answers

Insert an element at a specific index in a list and return the updated list

I have this: >>> a = [1, 2, 4] >>> print a [1, 2, 4] >>> print a.insert(2, 3) None >>> print a [1, 2, 3, 4] >>> b = a.insert(3, 6) >>> print b None >>> print a [1, 2, 3, 6, 4] Is there a way I can get the updated list as the result, instead of…
ATOzTOA
  • 34,814
  • 22
  • 96
  • 117
171
votes
4 answers

PostgreSQL: insert from another table

I'm trying to insert data to a table from another table and the tables have only one column in common. The problem is, that the TABLE1 has columns that won't accept null values so I can't leave them empty and I can't get them from the TABLE2. I have…
Seerumi
  • 1,937
  • 3
  • 18
  • 16
171
votes
9 answers

What is the preferred/idiomatic way to insert into a map?

I have identified four different ways of inserting elements into a std::map: std::map function; function[0] = 42; function.insert(std::map::value_type(0, 42)); function.insert(std::pair(0,…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
168
votes
9 answers

Python pandas insert list into a cell

I have a list 'abc' and a dataframe 'df': abc = ['foo', 'bar'] df = A B 0 12 NaN 1 23 NaN I want to insert the list into cell 1B, so I want this result: A B 0 12 NaN 1 23 ['foo', 'bar'] Ho can I do that? 1) If I use…
ragesz
  • 9,009
  • 20
  • 71
  • 88
137
votes
14 answers

How to insert multiple rows from array using CodeIgniter framework?

I'm passing a large dataset into a MySQL table via PHP using insert commands and I'm wondering if it's possible to insert approximately 1000 rows at a time via a query other than appending each value on the end of a mile-long string and then…
toofarsideways
  • 3,956
  • 2
  • 31
  • 51
136
votes
7 answers

How can I insert values into a table, using a subquery with more than one result?

I really would appreciate your help. Probably it's a quite simple problem to solve - but I'm not the one .. ;-) I have two tables in SQL Server: article prices Now I want to select a certain set of ids and insert some entries into the prices-table…
Futuretec
  • 1,371
  • 2
  • 9
  • 4
124
votes
18 answers

Add (insert) a column between two columns in a data.frame

I have a data frame that has columns a, b, and c. I'd like to add a new column d between b and c. I know I could just add d at the end by using cbind but how can I insert it in between two columns?
Mark
  • 10,754
  • 20
  • 60
  • 81
123
votes
3 answers

How to insert current datetime in postgresql insert query

INSERT into Group (Name,CreatedDate) VALUES ('Test',UTC_TIMESTAMP(), 1); This is the query I have used for mysql to insert current date time. When I am using this in postgresql, I am getting below error. HINT: No function matches the given…
Shesha
  • 1,857
  • 6
  • 21
  • 28
121
votes
7 answers

Insert element at the beginning of the list in dart

I am just creating a simple ToDo App in Flutter. I am managing all the todo tasks on the list. I want to add any new todo tasks at the beginning of the list. I am able to use this workaround kind of thing to achieve that. Is there any better way to…
Ropali Munshi
  • 2,757
  • 4
  • 22
  • 45
121
votes
6 answers

MySQL Error 1264: out of range value for column

As I SET cust_fax in a table in MySQL like this: cust_fax integer(10) NOT NULL, and then I insert value like this: INSERT INTO database values ('3172978990'); but then it say `error 1264` out of value for column And I want to know where the…
Cin
  • 1,343
  • 2
  • 9
  • 9
117
votes
3 answers

c# datatable insert column at position 0

does anyone know the best way to insert a column in a datatable at position 0?
Grant
  • 11,138
  • 32
  • 94
  • 140
116
votes
9 answers

java: use StringBuilder to insert at the beginning

I could only do this with String, for example: String str = ""; for (int i = 0; i < 100; i++) { str = i + str; } Is there a way to achieve this with StringBuilder? Thanks.
user685275
  • 2,097
  • 8
  • 26
  • 32
112
votes
4 answers

MySql Table Insert if not exist otherwise update

UPDATE AggregatedData SET datenum="734152.979166667", Timestamp="2010-01-14 23:30:00.000" WHERE datenum="734152.979166667"; It works if the datenum exists, but I want to insert this data as a new row if the datenum does not exist. UPDATE the…
Mokus
  • 10,174
  • 18
  • 80
  • 122
112
votes
2 answers

Why are 2 rows affected in my `INSERT ... ON DUPLICATE KEY UPDATE`?

I'm doing an INSERT ... ON DUPLICATE KEY UPDATE for a PRIMARY KEY in the following table: DESCRIBE users_interests; +------------+---------------------------------+------+-----+---------+-------+ | Field | Type |…
Josh Smith
  • 14,674
  • 18
  • 72
  • 118