question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select Into Insert question

See original GitHub issue

Hi. 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:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
panthernetcommented, Nov 3, 2022

oracle doesn’t support returning/output clause so it is expected for InsertWith*Identity API to generate unsupported sql. If you have an idea how oracle-compatible sql should look here - we could fix it

Sad but true. The only workaround I’ve found so far: https://stackoverflow.com/questions/49195453/alternative-to-returning-with-insert-select

Maybe something similar #2831

Thanks, this is interesting feature to keep in mind but won’t help with the current issue 😃

1reaction
MaceWinducommented, Nov 3, 2022

oracle doesn’t support returning/output clause so it is expected for InsertWith*Identity API to generate unsupported sql. If you have an idea how oracle-compatible sql should look here - we could fix it

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found