snippetsqlMinor
format() is a nondeterministic built-in string function... right?
Viewed 0 times
builtformatfunctionnondeterministicstringright
Problem
Before I post a connect item regarding the lack of documentation about this, will someone confirm that I am not simply missing something here?
On the docs page where
"All built-in string functions are deterministic." - String Functions (Transact-SQL)
There is also no mention of
However, when attempting to create a persisted computed column:
Returns the following error:
Computed column 'date_formatted_01' in table 't' cannot be persisted because the column is non-deterministic.
The documentation states that
If the culture argument is not provided, the language of the current
session is used.
but adding a culture argument doesn't change things
This also fails
rextester demo: http://rextester.com/ZMS22966
dbfiddle.uk demo: http://dbfiddle.uk/?rdbms=sqlserver_next&fiddle=7fc57d1916e901cb561b551af144aed6
On the docs page where
format is listed as a string function: "All built-in string functions are deterministic." - String Functions (Transact-SQL)
There is also no mention of
format being nondeterministic on related pages:- Deterministic and Nondeterministic Functions
- FORMAT (Transact-SQL)
However, when attempting to create a persisted computed column:
create table t (date_col date);
insert into t values (getdate());
alter table t add date_formatted_01 as format(date_col,'YYYY') persisted;Returns the following error:
Computed column 'date_formatted_01' in table 't' cannot be persisted because the column is non-deterministic.
The documentation states that
If the culture argument is not provided, the language of the current
session is used.
but adding a culture argument doesn't change things
This also fails
alter table t add date_formatted_02 as format(date_col, 'd', 'en-US' ) persistedrextester demo: http://rextester.com/ZMS22966
dbfiddle.uk demo: http://dbfiddle.uk/?rdbms=sqlserver_next&fiddle=7fc57d1916e901cb561b551af144aed6
Solution
The
The
Likewise, String Functions (Transact-SQL) now includes:
All built-in string functions except
FORMAT documentation has now been updated (in response to your Connect item) to say:The
FORMAT function is nondeterministic.Likewise, String Functions (Transact-SQL) now includes:
All built-in string functions except
FORMAT are deterministic.Context
StackExchange Database Administrators Q#174739, answer score: 7
Revisions (0)
No revisions yet.