I have a database table as follows:
CREATE TABLE some_table
(
price FLOAT NOT NULL,
size FLOAT NOT NULL,
retrieved DATETIME2 DEFAULT SYSUTCDATETIME(),
runner_id INT NOT NULL,
FOREIGN KEY (runner_id) REFERENCES runner(id),
PRIMARY KEY (retrieved, price, size, runner_id)
);
CREATE INDEX some_table_index ON some_table (runner_id);
This table is populated by sets of price/size data retrieved from a web service which is essentially time-series in nature. As far as I can tell (and I have put some comparison logic in my code to make sure) price and size are never the duplicated in a single set of entries retrieved from the web service. They may however be duplicated in subsequent requests for price/size data related to the same runner.
I am getting intermittent primary key constraint duplicate key exceptions even though I am forming my key off a high resolution date time value as well as the rest of the table columns. At this stage I am considering dropping the composite key in favor of an auto-generated primary key. Can anyone suggest why this might be happening based on the table schema? I consider it unlikely that I am trying to insert two separate sets of price/size data with duplicate values simultaneously given the nature of the code and resolution of the date time value. I guess it is possible though - I am using asynchronous methods to interact with the database and web service.
Thanks