Select Into Insert question
See original GitHub issueHi. I have the following query:
db.Scenarios.Where(a => a.Id == id)
.Into(db.Scenarios)
.Value(s => s.Name, name)
.Value(s => s.Value, s => s.Value)
.Insert();
Is it possible to perform insert of the selected entry modifying only some of it’s properties and allowing all the others to be copied automatically? Right now I have to list ALL the properties to copy the entry. Or may be there’s a better way to copy an entry in the same table modifying only some props?
Also I want to be able to fetch new entry ID from:
db.Scenarios.Where(a => a.Id == id)
.Into(db.Scenarios)
.Value(s => s.Name, name)
.Value(s => s.Value, s => s.Value)
.InsertWithInt64Identity();
But it throws an exception ORA-00933: sql command not properly ended
. Is there any work around?
Generated query:
DECLARE @Name Varchar2(9) -- String
SET @Name = 'COPY'
DECLARE @id Int64
SET @id = 61
DECLARE @IDENTITY_PARAMETER Decimal
SET @IDENTITY_PARAMETER = NULL
INSERT INTO SCENARIOS
(
NAME,
VALUE
)
SELECT
:Name,
a.VALUE
FROM
SCENARIOS a
WHERE
a.ID = :id
RETURNING
ID INTO :IDENTITY_PARAMETER
Environment details
Linq To DB
version: 3.4.3.0
Database (with version): ORACLE 21c
ADO.NET Provider (with version): ODP.NET, Managed Driver 4.122.19.1
Operating system: WIN 10
.NET Version: 4.5.2
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
INSERT INTO SELECT statement overview and examples
This article covers the INSERT INTO SELECT statement along with its syntax, examples and use cases.
Read more >SQL Server: Performance Insert Into vs Select Into
We conducted performance testing, and seems select into is slightly faster. What are good principles in figuring which is faster and why? I ......
Read more >SQL INSERT INTO SELECT Statement
The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target...
Read more >sql - Insert into ... values ( SELECT ... FROM ... ...
I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible for many database engines,...
Read more >SELECT INTO Statement in SQL
SELECT INTO statement in SQL is generally used for bulk copy purposes. We could copy the whole data from one table into another...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sad but true. The only workaround I’ve found so far: https://stackoverflow.com/questions/49195453/alternative-to-returning-with-insert-select
Thanks, this is interesting feature to keep in mind but won’t help with the current issue 😃
oracle doesn’t support
returning/output
clause so it is expected forInsertWith*Identity
API to generate unsupported sql. If you have an idea how oracle-compatible sql should look here - we could fix it