sql-returning

JDBC Batch INSERT, RETURNING IDs

╄→гoц情女王★ 提交于 2021-01-28 09:13:24
问题 is there any way to get the values of affected rows using RETURNING INTO ? I have to insert the same rows x times and get the ids of inserted rows. The query looks like below: public static final String QUERY_FOR_SAVE = "DECLARE " + " resultId NUMBER ; " + "BEGIN " + " INSERT INTO x " + " (a, b, c, d, e, f, g, h, i, j, k, l, m) " + " values (sequence.nextVal, :a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l) " + " RETURNING a INTO :resultId;" + "END;"; Now i can add thise query to batch, in

JDBC Batch INSERT, RETURNING IDs

北慕城南 提交于 2021-01-28 09:07:02
问题 is there any way to get the values of affected rows using RETURNING INTO ? I have to insert the same rows x times and get the ids of inserted rows. The query looks like below: public static final String QUERY_FOR_SAVE = "DECLARE " + " resultId NUMBER ; " + "BEGIN " + " INSERT INTO x " + " (a, b, c, d, e, f, g, h, i, j, k, l, m) " + " values (sequence.nextVal, :a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l) " + " RETURNING a INTO :resultId;" + "END;"; Now i can add thise query to batch, in

Return updated row attributes on UPDATE

时光毁灭记忆、已成空白 提交于 2020-12-29 05:31:05
问题 My query is as follow: UPDATE t1 SET t1.foreign_key = (SELECT id FROM t2 WHERE t2.col = %s ) WHERE t1.col = %s How do I return some attributes of the updated row in the table in the same query? 回答1: Use the RETURNING clause. The optional RETURNING clause causes UPDATE to compute and return value(s) based on each row actually updated. Any expression using the table's columns, and/or columns of other tables mentioned in FROM , can be computed. The new (post-update) values of the table's columns

Return updated row attributes on UPDATE

只愿长相守 提交于 2020-12-29 05:30:37
问题 My query is as follow: UPDATE t1 SET t1.foreign_key = (SELECT id FROM t2 WHERE t2.col = %s ) WHERE t1.col = %s How do I return some attributes of the updated row in the table in the same query? 回答1: Use the RETURNING clause. The optional RETURNING clause causes UPDATE to compute and return value(s) based on each row actually updated. Any expression using the table's columns, and/or columns of other tables mentioned in FROM , can be computed. The new (post-update) values of the table's columns

Return updated row attributes on UPDATE

折月煮酒 提交于 2020-12-29 05:29:47
问题 My query is as follow: UPDATE t1 SET t1.foreign_key = (SELECT id FROM t2 WHERE t2.col = %s ) WHERE t1.col = %s How do I return some attributes of the updated row in the table in the same query? 回答1: Use the RETURNING clause. The optional RETURNING clause causes UPDATE to compute and return value(s) based on each row actually updated. Any expression using the table's columns, and/or columns of other tables mentioned in FROM , can be computed. The new (post-update) values of the table's columns

INSERT INTO … FROM SELECT … RETURNING id mappings

非 Y 不嫁゛ 提交于 2020-01-10 02:50:06
问题 I'm using PostgreSQL 9.3. I want to duplicate some of the db records. Since I'm using an auto-increment pk id for the table, I want to get back the id mappings from the generated ids of duplicated records to the original ones. For example, say I have a table posts with 2 records in it: [{'id': 1, 'title': 'first'} , {'id': 2. 'title': 'second'}] With SQL: INSERT INTO posts (title) SELECT title FROM posts RETURNING id, ?? I expect to see mappings like: [{'id': 3, 'from_id': 1} , {'id': 4,

Alternative to RETURNING with INSERT…SELECT

穿精又带淫゛_ 提交于 2019-12-24 16:05:57
问题 There's this scenario which involves inserting into a table by copying some columns from another table and returning the generated key out of this insert. Using Oracle Database. Which basically by instinct result to writing this query. INSERT INTO TBL_XXX SELECT COLA, COLB, COLC FROM TBL_YYY RETURNING COLA INTO COL_RES Which is not allowed for some valid reason. Is there an alternative to this? 回答1: You're using the insert into ... select from construct. So potentially your statement will

One INSERT with multiple SELECT

喜你入骨 提交于 2019-12-24 14:02:42
问题 I've already read this, this and this, but I cant make this SQL work: INSERT INTO main_phrase (description) VALUES ('Mot commun féminin pluriel animaux'); /* ERROR: */ WITH t1 AS ( SELECT id FROM main_phrase WHERE description='Mot commun féminin pluriel animaux' ), t2 AS ( SELECT id FROM main_groupecategories WHERE description='Mot commun féminin pluriel animaux' ) INSERT INTO main_phrasegroupecategories (phrase_id, groupe_categories_id) VALUES (t1.id, t2.id); I get: ERROR: missing entry for