开发者

Teradata equivalent of persisted computed column (in SQL Server)

开发者 https://www.devze.com 2022-12-22 02:20 出处:网络
We have a few tables with persisted computed columns in SQL Server. Is there an equivalent of this in Teradata?And, if so, what is the syntax and are there any limitations?

We have a few tables with persisted computed columns in SQL Server.

Is there an equivalent of this in Teradata? And, if so, what is the syntax and are there any limitations?

The particular computed columns I am looking at conform some account numbers by removing leading zeros - an index is also created on this conformed account number:

ACCT_NUM_std AS ISNULL(CONVERT(varchar(39),
                               SUBSTRING(LTRIM(RTRIM([ACCT_NUM])),
                                         PATINDEX('%[^0]%',
                                                  LTRIM(RTRIM([ACCT_NUM])) + '.'
                                                 ),
                                         LEN(LTRIM(RTRIM([ACCT_NUM])))
                                        )
                              ),
                       ''
                      ) PERSISTED

With the Teradata TRIM function, the trimming part would be a little simpler:

ACCT_NUM_std AS COALESCE(CAST(TRIM(LEADING '0' FROM TRIM(BOTH FROM ACCT_NUM))) AS varchar(39)),
                         ''
                        )

I guess I could just make this a normal column and put the code to standardize t开发者_如何学Gohe account numbers in all the processes which insert into the table. We did this to put the standardization code in one place.


As far as I have been able to determine, Teradata does not support computed columns in tables.

I adopted the strategy of having all the various inserts use the same code, which has resulted in code duplication, unfortunately.

0

精彩评论

暂无评论...
验证码 换一张
取 消