Using a function in a primary key field [message #4973] |
Wed, 02 September 2015 01:50 |
rafs
Messages: 69 Registered: May 2015
|
Member |
|
|
I also ran into a situation where I have a compound UNIQUE key (some_timestamp, some_type_id), and both fields are NOT NULL.
I wanted some_timestamp to get the value now()::timestamp(0) with time zone.
(This truncates the miliseconds from the timestamp which I don't want because I want only one record of this type per second.
But it seems the framework will test the UNIQUENESS and fail since now() is not a real value yet.
[Updated on: Wed, 02 September 2015 01:52] Report message to a moderator
|
|
|
Re: Using a function in a primary key field [message #4985 is a reply to message #4973] |
Wed, 02 September 2015 12:12 |
AJM
Messages: 2369 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
That is correct. If you set the value of a field to a function as in "now()" then the value from that function will not be known until the query is executed. You cannot use functions for unique keys as RADICORE will test for uniqueness before the query is executed.
You should remove "now()" from the default value in the Data Dictionary and set the "Auto Insert" property instead. This will allow the framework to obtain the correct value before the test for uniqueness is performed.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|