powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / Deterministic Computed Column DATE on JSON_VALUE
2 сообщений из 2, страница 1 из 1
Deterministic Computed Column DATE on JSON_VALUE
    #39597379
deterministic_json
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Подскажите, есть какие-нибудь варианты, сделать так, чтобы была computed column, и затем можно было навесить на нее INDEX при работе с JSON?

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
USE tempdb;
IF OBJECT_ID('T', 'U') IS NOT NULL
    DROP TABLE T;
CREATE TABLE T
(
    ID INT NOT NULL IDENTITY,
    Attributes VARCHAR(MAX),
    Date1 AS JSON_VALUE(Attributes,'$.Date'),
	Date2 AS CAST(JSON_VALUE(Attributes,'$.Date') AS DATE),
);
INSERT T(Attributes)
SELECT '{  "Date" : "2017-12-08" }' UNION SELECT '{  "Date" : "2017-12-10" }'
GO
CREATE NONCLUSTERED INDEX IX_Date1 ON T(Date1);
CREATE NONCLUSTERED INDEX IX_Date2 ON T(Date2);
GO



На выходе ошибка:
Код: sql
1.
2.
3.
4.
(2 rows affected)
Warning! The maximum key length for a nonclustered index is 1700 bytes. The index 'IX_Date1' has maximum length of 8000 bytes. For some combination of large values, the insert/update operation will fail.
Msg 2729, Level 16, State 1, Line 15
Column 'Date2' in table 'T' cannot be used in an index or statistics or as a partition key because it is non-deterministic.



В первом случае не нравится т.к. колонка становится вида строка и поиск работает только в таком формате:

Код: sql
1.
2.
SELECT * FROM dbo.T AS T
WHERE T.Date1='2017-12-08'


а так не работает
Код: sql
1.
2.
SELECT * FROM dbo.T AS T
WHERE T.Date1='20171208'



Про Deterministic CONVERT/CAST читал, может есть все таки какие-то возможности?

Спасибо
...
Рейтинг: 0 / 0
Deterministic Computed Column DATE on JSON_VALUE
    #39597511
aleks222
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Смотрим в книгу - видим фигу
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
CONVERT Deterministic unless one of these conditions exists:



 Source type is sql_variant.

 Target type is sql_variant and its source type is nondeterministic.

 Source or target type is datetime or smalldatetime, the other source or target type is a character string, and a nondeterministic style is specified. To be deterministic, the style parameter must be a constant. Additionally, styles less than or equal to 100 are nondeterministic, except for styles 20 and 21.  Styles greater than 100 are deterministic , except for styles 106, 107, 109 and 113. 
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / Deterministic Computed Column DATE on JSON_VALUE
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]