Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
2 answers
1k 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='...
user13581602's user avatar
5 votes
1 answer
798 views

Include non-inserted rows as result of INSERT INTO ... RETURNING

I'm using PostgreSQL 11. I want to conditionally insert values into a table while having the result of the insertion include a null for each row of the input which did not result in an insertion. For ...
Ell's user avatar
  • 153
0 votes
0 answers
1k views

Multiple sub query in insert statement for postgreSQL

I am trying to insert into table with multiple queries. And its not working, here is my work. insert into post_topics_ta (id,post_id,topic_id,confidence_score) SELECT * FROM post_topics WHERE ...
prabhu's user avatar
  • 23
2 votes
1 answer
5k views

multiple insert queries after a set of with's

I am trying to have a reproducible way to populate a database with some test data. Suppose (an overly simplified example with) three base tables: name, city, job, and two relationship tables: name-...
ahron's user avatar
  • 823
5 votes
1 answer
10k views

Insert Into table ommitting columns that have default values

I have a PostgreSQL database with lots of tables of the same structure, 36 columns in total: CREATE TABLE some_schema.some_table ( id integer NOT NULL DEFAULT nextval('some_schema.id_seq'::...
Alex's user avatar
  • 153
1 vote
0 answers
95 views

How to populate a 'map' table from words of a text?

Having the database structure that follows: CREATE TABLE articles ( article_id int(11) unsigned NOT NULL AUTO_INCREMENT, article text, PRIMARY KEY(article_id) ) ENGINE=InnoDB; CREATE TABLE words ( ...
Googlebot's user avatar
  • 4,531
0 votes
1 answer
62 views

Insert Into with Select works in once instance, but not the other. Subquery error or incorrect data

I am trying to write a script that will combine specific survey results based on the demographs used in the survey. I have been able to write a script that adds demographs together to create a new ...
L.Moy's user avatar
  • 45
1 vote
1 answer
556 views

Using a subquery in place of a SELECT fieldname ...or how to achieve the same result?

My goal is to get a collection of ID's from Table 1 based on a query, a collection of ID's from Table 2 based on a query, and insert a new record into Table 3 for each permutation. Basically, this: ...
Nick's user avatar
  • 301
0 votes
2 answers
6k views

Insert query with a subquery

I want to insert somewhere around 400 rows into a table. All of the column values will be the same fixed value for most of the columns, with exception to one column which I want to pull from a fairly ...
jdillman's user avatar