MySQL - Virtual Column not handled in INSERT, UPDATE
See original GitHub issuePlease consider the following table:
CREATE TABLE `products` (
`ProductID` int(11) NOT NULL,
`ProductName` char(255) NOT NULL,
`data` json NOT NULL,
`jsonID` int(11) GENERATED ALWAYS AS (json_extract(`data`,'$.jsonID')) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
if I retrieve data from the DB, linq2sql behaviour is normal, but if I InsertOrReplace and item, this exception is fired: “The value specified for generated column ‘jsonID’ in table ‘products’ is not allowed” It happens because the MySQL connector tries to set a value in a column that is virtually generated (alias read-only). Please add a property attribute such as “ReadOnly” or “Virtual” that we can apply to the C# class to indicate linq2db that the column should not be inserted in the INSERT or UPDATE queries, but only in the SELECT query Thanks in advance, Luca
C# Class implementation
[Table(Name = "Products")]
public class Product
{
[PrimaryKey]
public int ProductID { get; set; }
[Column(Name = "ProductName"), NotNull]
public string Name { get; set; }
[Column(Name = "data")]
public string data { get; set; }
[Column(Name = "jsonID")]
public int jsonID { get; internal set;}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
mysql - INSERT INTO ... SELECT if destination column has ...
SELECT if the destination table adds some columns where some of them are GENERATED? The code calling this query is generic and has...
Read more >Virtual Columns and Effective Functional Indexes in InnoDB
The virtual columns are no longer materialized in the table. ... virtual columns when they need to be materialized (e.g. INSERT or UPDATE...
Read more >13.1.20.8 CREATE TABLE and Generated Columns
VIRTUAL : Column values are not stored, but are evaluated when rows are read, immediately after any BEFORE triggers. A virtual column takes...
Read more >13.1.9.2 ALTER TABLE and Generated Columns
Virtual generated columns cannot be altered to stored generated columns, or vice versa. To work around this, drop the column, then add it...
Read more >Generated columns (virtual & stored) do not update on ...
Description: I have an original replication setup consisting of two OLTP mysql instances (5.7.31 on Centos 7) and two OLAP (5.7.30 on ...
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
Try to use ColumnAttribute boolean properties: SkipOnInsert and SkipOnUpdate.
@visual1993, it is not a bug, this attribute works for different configurations. But i agree it would be great to throw informative exception that for the same configuration two attributes are defined.