tdsql-mcp 1.4.3__tar.gz → 1.4.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/PKG-INFO +2 -2
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/pyproject.toml +2 -1
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/aggregate-functions.md +16 -14
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/association-analysis.md +35 -9
- tdsql_mcp-1.4.5/skills/teradata-sql-analytics/syntax/authorization-objects.md +259 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/bit-byte-functions.md +25 -15
- tdsql_mcp-1.4.5/skills/teradata-sql-analytics/syntax/catalog-views.md +266 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/conditional.md +16 -8
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/data-cleaning.md +33 -44
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/data-exploration.md +34 -15
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/data-prep.md +55 -36
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/data-types-casting.md +8 -6
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/date-time.md +25 -11
- tdsql_mcp-1.4.5/skills/teradata-sql-analytics/syntax/fit-transform-pattern.md +123 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/geospatial.md +14 -6
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/guidelines.md +84 -42
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/hypothesis-testing.md +23 -19
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/index.md +10 -14
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/json-functions.md +21 -12
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/ml-functions.md +34 -24
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/ml-patterns.md +24 -17
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/model-evaluation.md +47 -36
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/numeric-functions.md +13 -7
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/object-store.md +39 -7
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/open-table-format.md +88 -34
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/path-analysis.md +23 -22
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/query-tuning.md +20 -23
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/sql-basics.md +38 -61
- tdsql_mcp-1.4.5/skills/teradata-sql-analytics/syntax/string-functions.md +352 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/text-analytics.md +39 -29
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-concepts.md +7 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-data-prep.md +9 -1
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-diagnostics.md +15 -12
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-dsp.md +13 -10
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-estimation.md +22 -10
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-forecasting.md +17 -17
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-formula-rules.md +11 -13
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/uaf-utility.md +24 -10
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/utility-functions.md +17 -12
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/vector-search.md +267 -17
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/window-functions.md +25 -10
- tdsql_mcp-1.4.3/skills/teradata-sql-analytics/syntax/authorization-objects.md +0 -173
- tdsql_mcp-1.4.3/skills/teradata-sql-analytics/syntax/catalog-views.md +0 -185
- tdsql_mcp-1.4.3/skills/teradata-sql-analytics/syntax/fit-transform-pattern.md +0 -94
- tdsql_mcp-1.4.3/skills/teradata-sql-analytics/syntax/string-functions.md +0 -74
- tdsql_mcp-1.4.3/uv.lock +0 -797
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/.claude-plugin/plugin.json +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/.env.example +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/.gitignore +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/CLAUDE.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/README.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/docs/architecture.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/requirements.txt +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/README.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/SKILL.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/ai-text-analytics.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/byom-model-loading.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/byom-scoring.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/embeddings.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/llm-providers.md +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/src/tdsql_mcp/__init__.py +0 -0
- {tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/src/tdsql_mcp/server.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: tdsql-mcp
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.5
|
|
4
4
|
Summary: MCP server for Teradata Vantage — SQL execution and native analytics function reference for AI agents
|
|
5
5
|
Project-URL: Homepage, https://github.com/ksturgeon-td/tdsql-mcp
|
|
6
6
|
Project-URL: Repository, https://github.com/ksturgeon-td/tdsql-mcp
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tdsql-mcp"
|
|
7
|
-
version = "1.4.
|
|
7
|
+
version = "1.4.5"
|
|
8
8
|
description = "MCP server for Teradata Vantage — SQL execution and native analytics function reference for AI agents"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -41,3 +41,4 @@ tdsql-mcp = "tdsql_mcp.server:main"
|
|
|
41
41
|
|
|
42
42
|
[tool.hatch.build.targets.wheel]
|
|
43
43
|
packages = ["src/tdsql_mcp"]
|
|
44
|
+
|
{tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/aggregate-functions.md
RENAMED
|
@@ -24,24 +24,24 @@ VAR_SAMP(col) -- sample variance
|
|
|
24
24
|
-- Exact (sorts all data — can be slow on large sets)
|
|
25
25
|
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY col) -- median
|
|
26
26
|
PERCENTILE_DISC(0.25) WITHIN GROUP (ORDER BY col) -- 25th percentile (discrete)
|
|
27
|
-
|
|
28
|
-
-- Approximate (fast, uses HLL sketch — Vantage)
|
|
29
|
-
APPROX_PERCENTILE(col, 0.5)
|
|
30
|
-
APPROX_PERCENTILE(col, 0.95)
|
|
27
|
+
-- No native approximate percentile function found on Teradata 20.00.30.76.
|
|
31
28
|
```
|
|
32
29
|
|
|
33
|
-
##
|
|
30
|
+
## Distinct Count
|
|
34
31
|
```sql
|
|
35
|
-
|
|
36
|
-
APPROX_COUNT_DISTINCT
|
|
32
|
+
COUNT(DISTINCT col)
|
|
33
|
+
-- No native APPROX_COUNT_DISTINCT found on Teradata 20.00.30.76.
|
|
37
34
|
```
|
|
38
35
|
|
|
39
36
|
## String Aggregation
|
|
40
37
|
```sql
|
|
41
|
-
-- Concatenate values into one string
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
-- Concatenate values into one delimited string: aggregate, cast, and trim the trailing comma
|
|
39
|
+
-- Note: wrapping with XMLELEMENT keeps XML tags in output — use TRIM + CAST instead
|
|
40
|
+
SELECT dept,
|
|
41
|
+
TRIM(TRAILING ',' FROM CAST(XMLAGG(TRIM(col) || ',' ORDER BY col) AS VARCHAR(1000))) AS vals
|
|
42
|
+
FROM db.t
|
|
43
|
+
GROUP BY dept;
|
|
44
|
+
-- LISTAGG and STRING_AGG are not available on Teradata 20.00.30.76.
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
## GROUP BY Variants
|
|
@@ -52,9 +52,11 @@ SELECT dept, SUM(salary) FROM db.t GROUP BY dept;
|
|
|
52
52
|
-- Multiple grouping sets in one pass
|
|
53
53
|
GROUP BY GROUPING SETS ((dept), (region), (dept, region), ())
|
|
54
54
|
|
|
55
|
-
--
|
|
55
|
+
-- CUBE produces the same result as the four-set GROUPING SETS example above
|
|
56
|
+
GROUP BY CUBE(dept, region) -- all combinations + grand total
|
|
57
|
+
|
|
58
|
+
-- ROLLUP is smaller: (dept, region), (dept), and the grand total () only
|
|
56
59
|
GROUP BY ROLLUP(dept, region) -- all prefixes + grand total
|
|
57
|
-
GROUP BY CUBE(dept, region) -- all combinations
|
|
58
60
|
|
|
59
61
|
-- Identify which grouping a row belongs to
|
|
60
62
|
GROUPING(dept) -- 1 if dept is aggregated away, 0 if not
|
|
@@ -77,7 +79,7 @@ SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) AS active_count
|
|
|
77
79
|
AVG(NULLIFZERO(amount))
|
|
78
80
|
|
|
79
81
|
-- Max of a filtered subset
|
|
80
|
-
MAX(CASE WHEN category = 'A' THEN value END)
|
|
82
|
+
MAX(CASE WHEN category = 'A' THEN "value" END) -- value is a reserved word; must be quoted
|
|
81
83
|
```
|
|
82
84
|
|
|
83
85
|
## Common Patterns
|
{tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/association-analysis.md
RENAMED
|
@@ -12,7 +12,6 @@ Discovers frequent patterns (itemsets) and association rules in transactional da
|
|
|
12
12
|
```sql
|
|
13
13
|
SELECT * FROM TD_Apriori(
|
|
14
14
|
ON { db.table | db.view | (query) } AS InputTable [ PARTITION BY ANY ]
|
|
15
|
-
[ OUT TABLE OutputTable('db.pattern_table') ] -- optional; writes output to a named table
|
|
16
15
|
USING
|
|
17
16
|
TargetColumn('item_col') -- required; column containing item data; max 1
|
|
18
17
|
[ IDColumn('transaction_id_col') ] -- required for sparse input; groups items into transactions
|
|
@@ -24,10 +23,20 @@ SELECT * FROM TD_Apriori(
|
|
|
24
23
|
[ PatternsOrRules('Patterns') ] -- optional; default 'Patterns'
|
|
25
24
|
-- 'Patterns' — frequent itemsets only
|
|
26
25
|
-- 'Rules' — association rules with metrics
|
|
27
|
-
--
|
|
26
|
+
-- 'Both' is rejected (error 7810); run the function twice to get both outputs
|
|
28
27
|
[ Support(0.01) ] -- optional; min itemset frequency as proportion
|
|
29
28
|
-- of total transactions; range (0,1]; default 0.01
|
|
29
|
+
-- threshold is inclusive (itemsets at exactly the threshold are returned)
|
|
30
30
|
) AS t;
|
|
31
|
+
|
|
32
|
+
-- TD_Apriori has no OUT TABLE clause (error 7810). To save the output, wrap the call in CREATE TABLE AS.
|
|
33
|
+
-- Use MULTISET so repeated rows are not dropped:
|
|
34
|
+
CREATE MULTISET TABLE db.pattern_table AS (
|
|
35
|
+
SELECT * FROM TD_Apriori(
|
|
36
|
+
ON db.baskets AS InputTable PARTITION BY ANY
|
|
37
|
+
USING TargetColumn('item') IDColumn('txn') Support(0.2)
|
|
38
|
+
) AS t
|
|
39
|
+
) WITH DATA;
|
|
31
40
|
```
|
|
32
41
|
|
|
33
42
|
**Input formats:**
|
|
@@ -37,7 +46,22 @@ SELECT * FROM TD_Apriori(
|
|
|
37
46
|
| Dense | One row per transaction; items in a single delimited cell in `TargetColumn` | Not used |
|
|
38
47
|
| Sparse | One row per item; `IDColumn` groups items into a transaction | Required |
|
|
39
48
|
|
|
40
|
-
**
|
|
49
|
+
> **Character set:** `TargetColumn` must be a LATIN column. Unicode input causes `Itemset` values to contain NUL characters between every letter (e.g. `CHAR_LENGTH('bread,milk')` returns 19 instead of 10). Convert Unicode columns first:
|
|
50
|
+
> ```sql
|
|
51
|
+
> SELECT * FROM TD_Apriori(
|
|
52
|
+
> ON (SELECT TRANSLATE(items USING UNICODE_TO_LATIN) AS items FROM db.baskets) AS InputTable PARTITION BY ANY
|
|
53
|
+
> USING TargetColumn('items') InputDelimiter(',') Support(0.2)
|
|
54
|
+
> ) AS t;
|
|
55
|
+
> ```
|
|
56
|
+
> This was observed on dense input. Sparse Unicode input was not tested.
|
|
57
|
+
|
|
58
|
+
> **Single-item itemsets:** Without `PartitionColumns`, `Patterns` output contains only itemsets of 2 to `MaxLen` items — single-item itemsets are not returned. With `PartitionColumns`, single items above the support threshold are included. To compute single-item support without a partition, use a separate query:
|
|
59
|
+
> ```sql
|
|
60
|
+
> SELECT item, COUNT(DISTINCT txn) * 1.0 / (SELECT COUNT(DISTINCT txn) FROM db.baskets) AS support
|
|
61
|
+
> FROM db.baskets GROUP BY item;
|
|
62
|
+
> ```
|
|
63
|
+
|
|
64
|
+
**Output — Patterns** (`PatternsOrRules('Patterns')`):
|
|
41
65
|
|
|
42
66
|
| Column | Type | Description |
|
|
43
67
|
|--------|------|-------------|
|
|
@@ -45,15 +69,15 @@ SELECT * FROM TD_Apriori(
|
|
|
45
69
|
| `Itemset` | VARCHAR | Comma-separated (or `OutputDelimiter`) set of items |
|
|
46
70
|
| `Support` | REAL | Proportion of transactions containing this itemset |
|
|
47
71
|
|
|
48
|
-
**Output — Rules** (`PatternsOrRules('Rules')`
|
|
72
|
+
**Output — Rules** (`PatternsOrRules('Rules')`):
|
|
49
73
|
|
|
50
74
|
| Column | Type | Description |
|
|
51
75
|
|--------|------|-------------|
|
|
52
76
|
| `partition_column(s)` | ANY | Partition pass-through columns |
|
|
53
77
|
| `Antecedent` | VARCHAR | The "if" item(s) in the rule |
|
|
54
78
|
| `Consequence` | VARCHAR | The "then" item(s) in the rule |
|
|
55
|
-
| `
|
|
56
|
-
| `Conse_Item_Cnt` |
|
|
79
|
+
| `Ante_Item_Cnt` | INTEGER | Number of items in the antecedent |
|
|
80
|
+
| `Conse_Item_Cnt` | INTEGER | Number of items in the consequence |
|
|
57
81
|
| `cntb` | INTEGER | Co-occurrence count of antecedent and consequence |
|
|
58
82
|
| `Cnt_Antecedent` | INTEGER | Occurrence count of antecedent |
|
|
59
83
|
| `Cnt_Consequence` | INTEGER | Occurrence count of consequence |
|
|
@@ -82,7 +106,8 @@ SELECT * FROM TD_CFilter(
|
|
|
82
106
|
[ PartitionColumns('region_col') ] -- optional; partition input and output; max 10
|
|
83
107
|
-- output is nondeterministic unless each
|
|
84
108
|
-- partition_col is unique within TransactionIDColumns
|
|
85
|
-
[ MaxDistinctItems(100) ] -- optional;
|
|
109
|
+
[ MaxDistinctItems(100) ] -- optional; maximum number of distinct items in one transaction; default 100
|
|
110
|
+
-- transactions with more items are silently excluded from all counts
|
|
86
111
|
) AS t;
|
|
87
112
|
```
|
|
88
113
|
|
|
@@ -100,9 +125,10 @@ SELECT * FROM TD_CFilter(
|
|
|
100
125
|
| `support` | REAL | `cntb / tran_cnt` — proportion of transactions containing both items |
|
|
101
126
|
| `confidence` | REAL | `cntb / cnt1` — proportion of item1 transactions that also contain item2 |
|
|
102
127
|
| `lift` | REAL | `support(A∩B) / (support(A) × support(B))` — >1 positive, =1 independent, <1 negative |
|
|
103
|
-
| `z_score` | REAL | `(cntb - mean(cntb)) /
|
|
128
|
+
| `z_score` | REAL | `(cntb - mean(cntb)) / population_sd(cntb)` — co-occurrence significance; not calculated if all `cntb` values are equal |
|
|
104
129
|
|
|
105
130
|
> **Notes:**
|
|
106
131
|
> - Always pairwise — unlike `TD_Apriori`, does not produce itemsets of size > 2 or association rules
|
|
107
132
|
> - `TransactionIDColumns` accepts multiple columns (composite transaction key)
|
|
108
|
-
> - `
|
|
133
|
+
> - **Each pair appears in both directions** — `(bread, milk)` and `(milk, bread)` are separate rows, with `cnt1`, `cnt2`, and `confidence` swapped; the guide's "one row per item pair" is inaccurate
|
|
134
|
+
> - `z_score` uses the **population** standard deviation (not sample); it is null/absent when all `cntb` values are equal (sd = 0)
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# Teradata Authorization Objects
|
|
2
|
+
|
|
3
|
+
Authorization objects store external service credentials securely inside Teradata, decoupling
|
|
4
|
+
secrets from SQL code. They are used by NOS table operators (`READ_NOS`, `WRITE_NOS`),
|
|
5
|
+
external object access via `CREATE FOREIGN TABLE` and `CREATE DATALAKE`, and AI inference
|
|
6
|
+
functions (`AI_TextEmbeddings` and others).
|
|
7
|
+
|
|
8
|
+
Rather than embedding credentials directly in SQL, you reference a named authorization object.
|
|
9
|
+
Credentials are stored once, managed centrally, and access is controlled via standard
|
|
10
|
+
Teradata permissions.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## CREATE / REPLACE AUTHORIZATION
|
|
15
|
+
|
|
16
|
+
```sql
|
|
17
|
+
{ CREATE | REPLACE } AUTHORIZATION [DatabaseName.]authorization_name
|
|
18
|
+
[ AS { DEFINER | INVOKER } TRUSTED ]
|
|
19
|
+
{ user_password_auth | extended_auth }
|
|
20
|
+
|
|
21
|
+
-- Form 1: user_password_auth
|
|
22
|
+
USER 'user_value'
|
|
23
|
+
PASSWORD 'password_value'
|
|
24
|
+
[ SESSION_TOKEN 'session_token_value' ]
|
|
25
|
+
|
|
26
|
+
-- Form 2: extended_auth (AWS IAM role assumption only)
|
|
27
|
+
USING AUTHSERVICETYPE 'ASSUME_ROLE'
|
|
28
|
+
ROLENAME 'arn:aws:iam::account-id:role/role-name'
|
|
29
|
+
EXTERNALID 'external_id_value'
|
|
30
|
+
[ DURATION_SECONDS 'duration_in_seconds' ]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**`AS DEFINER` / `AS INVOKER` / `TRUSTED`:**
|
|
34
|
+
|
|
35
|
+
| Clause | Meaning |
|
|
36
|
+
|--------|---------|
|
|
37
|
+
| *(none — plain)* | **Recommended for DATALAKE and foreign tables.** Can be created in any database the creator has `CREATE AUTHORIZATION` on (including global databases). Referenced as `EXTERNAL SECURITY <db>.<auth>` with no keywords. |
|
|
38
|
+
| `AS DEFINER` | Shared access. Auth must be in the **same database** as the referencing object. Referenced as `EXTERNAL SECURITY DEFINER TRUSTED <auth>` (unqualified only — Error 3706 if qualified). |
|
|
39
|
+
| `AS INVOKER` | Exclusive access by the creating user; created in the user's own database. Referenced as `EXTERNAL SECURITY INVOKER TRUSTED <auth>`. |
|
|
40
|
+
| `TRUSTED` | Required **only** when using the `AS DEFINER` or `AS INVOKER` forms in an `EXTERNAL SECURITY` clause. Not needed for plain auth. |
|
|
41
|
+
|
|
42
|
+
**Form 2 — ASSUME_ROLE:**
|
|
43
|
+
- `AUTHSERVICETYPE` — only supported value is `'ASSUME_ROLE'`
|
|
44
|
+
- `ROLENAME` — ARN of the IAM role to assume
|
|
45
|
+
- `EXTERNALID` — external ID required by the IAM role trust policy
|
|
46
|
+
- `DURATION_SECONDS` — session duration 900–43200 seconds; default 3600; must not exceed the IAM role's max session duration
|
|
47
|
+
|
|
48
|
+
> **EXTERNAL SECURITY — the reference must match how the auth object was created:**
|
|
49
|
+
>
|
|
50
|
+
> | Auth created as | `EXTERNAL SECURITY` reference | Qualified `db.auth` allowed? |
|
|
51
|
+
> |---|---|---|
|
|
52
|
+
> | Plain (no `AS` clause) | `EXTERNAL SECURITY <db>.<auth>` (no keywords) | **Yes** — verified for DATALAKE and FOREIGN TABLE |
|
|
53
|
+
> | `AS DEFINER TRUSTED` | `EXTERNAL SECURITY DEFINER TRUSTED <auth>` | **No** — Error 3706; auth must be in the same DB as the object |
|
|
54
|
+
> | `AS INVOKER TRUSTED` | `EXTERNAL SECURITY INVOKER TRUSTED <auth>` | No |
|
|
55
|
+
>
|
|
56
|
+
> A mismatch raises Error 6953 (`authorization definition does not match`) or Error 3706.
|
|
57
|
+
>
|
|
58
|
+
> **Elastic Compute:** For DATALAKE objects, the auth object must be in a GLOBAL database
|
|
59
|
+
> so it replicates across all CE instances. For NOS foreign tables, place it in the same
|
|
60
|
+
> local or global database as the table.
|
|
61
|
+
>
|
|
62
|
+
> **GRANT EXECUTE:** After creating an auth object, grant `EXECUTE` so roles and databases
|
|
63
|
+
> can use it — see [Permissions](#permissions) below.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## NOS and OTF External Security Authorization
|
|
68
|
+
|
|
69
|
+
Used with `CREATE FOREIGN TABLE`, `CREATE DATALAKE`, `READ_NOS`, and `WRITE_NOS`.
|
|
70
|
+
The `USER` and `PASSWORD` fields map to object storage credentials, not API keys.
|
|
71
|
+
|
|
72
|
+
### Field Mapping — Object Storage Providers
|
|
73
|
+
|
|
74
|
+
| Storage system | USER | PASSWORD | SESSION_TOKEN |
|
|
75
|
+
|---|---|---|---|
|
|
76
|
+
| AWS (IAM user) | Access Key ID | Access Key Secret | Session Token *(optional — STS temporary creds only)* |
|
|
77
|
+
| Azure Shared Key | Storage Account Name | Storage Account Key | — |
|
|
78
|
+
| Azure SAS | Storage Account Name | Account SAS Token | — |
|
|
79
|
+
| GCS (S3 interop mode) | Access Key ID | Access Key Secret | — |
|
|
80
|
+
| GCS (native) | Client Email | Private Key | — |
|
|
81
|
+
| On-premises object store | Access Key ID | Access Key Secret | — |
|
|
82
|
+
| Public bucket | `''` (empty string) | `''` (empty string) | — |
|
|
83
|
+
|
|
84
|
+
### Examples
|
|
85
|
+
|
|
86
|
+
```sql
|
|
87
|
+
-- AWS: plain auth for OTF DATALAKE (no AS clause — plain auth + qualified ref is verified)
|
|
88
|
+
CREATE AUTHORIZATION global_db.aws_glue_auth
|
|
89
|
+
USER '<aws_access_key_id>'
|
|
90
|
+
PASSWORD '<aws_access_key_secret>';
|
|
91
|
+
|
|
92
|
+
-- AWS: ASSUME_ROLE for OTF DATALAKE or NOS
|
|
93
|
+
CREATE AUTHORIZATION global_db.aws_role_auth
|
|
94
|
+
USING AUTHSERVICETYPE 'ASSUME_ROLE'
|
|
95
|
+
ROLENAME '<arn:aws:iam::account-id:role/role-name>'
|
|
96
|
+
EXTERNALID '<external_id>'
|
|
97
|
+
DURATION_SECONDS '3600';
|
|
98
|
+
|
|
99
|
+
-- Azure Shared Key (Storage Account Name + Storage Account Key)
|
|
100
|
+
CREATE AUTHORIZATION global_db.azure_auth
|
|
101
|
+
USER '<storage_account_name>'
|
|
102
|
+
PASSWORD '<storage_account_key>';
|
|
103
|
+
|
|
104
|
+
-- Azure SAS (Storage Account Name + Account SAS Token)
|
|
105
|
+
CREATE AUTHORIZATION global_db.azure_sas_auth
|
|
106
|
+
USER '<storage_account_name>'
|
|
107
|
+
PASSWORD '<account_sas_token>';
|
|
108
|
+
|
|
109
|
+
-- GCS (S3 interop mode — Access Key ID + Secret)
|
|
110
|
+
CREATE AUTHORIZATION global_db.gcs_interop_auth
|
|
111
|
+
USER '<gcs_access_key_id>'
|
|
112
|
+
PASSWORD '<gcs_access_key_secret>';
|
|
113
|
+
|
|
114
|
+
-- GCS (native — Client Email + Private Key)
|
|
115
|
+
CREATE AUTHORIZATION global_db.gcs_native_auth
|
|
116
|
+
USER '<client_email>'
|
|
117
|
+
PASSWORD '<private_key>';
|
|
118
|
+
|
|
119
|
+
-- Public bucket (empty credentials)
|
|
120
|
+
CREATE AUTHORIZATION global_db.public_auth
|
|
121
|
+
USER ''
|
|
122
|
+
PASSWORD '';
|
|
123
|
+
|
|
124
|
+
-- NOS FOREIGN TABLE: AS DEFINER TRUSTED, auth in same DB as table, unqualified reference
|
|
125
|
+
CREATE AUTHORIZATION mydb.s3_ft_auth
|
|
126
|
+
AS DEFINER TRUSTED
|
|
127
|
+
USER '<aws_access_key_id>'
|
|
128
|
+
PASSWORD '<aws_access_key_secret>';
|
|
129
|
+
|
|
130
|
+
CREATE MULTISET FOREIGN TABLE mydb.orders_ft,
|
|
131
|
+
EXTERNAL SECURITY DEFINER TRUSTED s3_ft_auth -- unqualified; qualified raises Error 3706
|
|
132
|
+
USING ( LOCATION ('/S3/s3.amazonaws.com/<bucket>/<prefix>/') STOREDAS ('PARQUET') )
|
|
133
|
+
NO PRIMARY INDEX;
|
|
134
|
+
|
|
135
|
+
-- OTF DATALAKE: plain auth in GLOBAL database, qualified reference, no keywords
|
|
136
|
+
CREATE DATALAKE my_lake
|
|
137
|
+
EXTERNAL SECURITY CATALOG global_db.aws_glue_auth,
|
|
138
|
+
EXTERNAL SECURITY STORAGE global_db.aws_glue_auth
|
|
139
|
+
USING catalog_type ('glue') ... TABLE FORMAT iceberg;
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## AI Function Authorization
|
|
145
|
+
|
|
146
|
+
Used with `AI_TextEmbeddings`, `AI_Generate`, and other AI inference functions. The `USER`,
|
|
147
|
+
`PASSWORD`, and `SESSION_TOKEN` fields map to AI provider API credentials — **different
|
|
148
|
+
semantics from object storage auth above.**
|
|
149
|
+
|
|
150
|
+
### Field Mapping — AI Inference Providers
|
|
151
|
+
|
|
152
|
+
| Provider | USER | PASSWORD | SESSION_TOKEN |
|
|
153
|
+
|----------|------|----------|---------------|
|
|
154
|
+
| **AWS Bedrock** | Access Key ID | Access Key Secret | Session Token *(optional — STS only)* |
|
|
155
|
+
| **Azure OpenAI** | API Base URL (endpoint) | API Key | API Version *(required)* |
|
|
156
|
+
| **Google Cloud (Vertex)** | Project | Region | Access Token *(required)* |
|
|
157
|
+
| **NVIDIA NIM** | API Base URL | API Key | *(not used)* |
|
|
158
|
+
| **LiteLLM** | API Base URL | API Key | *(not used)* |
|
|
159
|
+
|
|
160
|
+
### Examples
|
|
161
|
+
|
|
162
|
+
```sql
|
|
163
|
+
-- AWS Bedrock (long-term IAM user — omit SESSION_TOKEN)
|
|
164
|
+
CREATE AUTHORIZATION db.td_gen_aws_auth
|
|
165
|
+
USER '<aws_access_key_id>'
|
|
166
|
+
PASSWORD '<aws_access_key_secret>';
|
|
167
|
+
|
|
168
|
+
-- AWS Bedrock (STS temporary credentials — include SESSION_TOKEN)
|
|
169
|
+
CREATE AUTHORIZATION db.td_gen_aws_auth
|
|
170
|
+
USER '<aws_access_key_id>'
|
|
171
|
+
PASSWORD '<aws_access_key_secret>'
|
|
172
|
+
SESSION_TOKEN '<aws_session_token>';
|
|
173
|
+
|
|
174
|
+
-- AWS Bedrock via IAM role assumption
|
|
175
|
+
CREATE AUTHORIZATION db.td_gen_aws_role_auth
|
|
176
|
+
USING AUTHSERVICETYPE 'ASSUME_ROLE'
|
|
177
|
+
ROLENAME 'arn:aws:iam::123456789012:role/teradata-bedrock-role'
|
|
178
|
+
EXTERNALID '<external_id>'
|
|
179
|
+
DURATION_SECONDS '3600';
|
|
180
|
+
|
|
181
|
+
-- Azure OpenAI (SESSION_TOKEN = API version string — required)
|
|
182
|
+
CREATE AUTHORIZATION db.td_gen_azure_auth
|
|
183
|
+
USER '<api_base_url>'
|
|
184
|
+
PASSWORD '<api_key>'
|
|
185
|
+
SESSION_TOKEN '2024-02-15-preview';
|
|
186
|
+
|
|
187
|
+
-- Google Cloud Vertex AI (SESSION_TOKEN = Access Token — required)
|
|
188
|
+
CREATE AUTHORIZATION db.td_gen_gcp_auth
|
|
189
|
+
USER '<gcp_project>'
|
|
190
|
+
PASSWORD '<gcp_region>'
|
|
191
|
+
SESSION_TOKEN '<gcp_access_token>';
|
|
192
|
+
|
|
193
|
+
-- NVIDIA NIM
|
|
194
|
+
CREATE AUTHORIZATION db.td_gen_nim_auth
|
|
195
|
+
USER '<nim_api_base_url>'
|
|
196
|
+
PASSWORD '<nim_api_key>';
|
|
197
|
+
|
|
198
|
+
-- LiteLLM
|
|
199
|
+
CREATE AUTHORIZATION db.td_gen_litellm_auth
|
|
200
|
+
USER '<litellm_base_url>'
|
|
201
|
+
PASSWORD '<litellm_api_key>';
|
|
202
|
+
|
|
203
|
+
-- Rotate credentials without dropping (use REPLACE)
|
|
204
|
+
REPLACE AUTHORIZATION db.td_gen_aws_auth
|
|
205
|
+
USER '<new_access_key>'
|
|
206
|
+
PASSWORD '<new_secret_key>';
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Permissions
|
|
212
|
+
|
|
213
|
+
### EXECUTE — allow a role or database to use an auth object
|
|
214
|
+
|
|
215
|
+
```sql
|
|
216
|
+
-- Grant to a role (preferred — access follows role membership)
|
|
217
|
+
GRANT EXECUTE ON db.my_auth TO analyst_role;
|
|
218
|
+
GRANT EXECUTE ON db.my_auth TO analyst_role WITH GRANT OPTION;
|
|
219
|
+
|
|
220
|
+
-- Grant at database level (covers all auth objects in the DB)
|
|
221
|
+
GRANT EXECUTE ON db TO analyst_role;
|
|
222
|
+
|
|
223
|
+
-- Revoke
|
|
224
|
+
REVOKE EXECUTE ON db.my_auth FROM analyst_role;
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### CREATE / DROP AUTHORIZATION
|
|
228
|
+
|
|
229
|
+
```sql
|
|
230
|
+
GRANT CREATE AUTHORIZATION ON db TO dba_user;
|
|
231
|
+
GRANT DROP AUTHORIZATION ON db TO dba_user;
|
|
232
|
+
REVOKE CREATE AUTHORIZATION ON db FROM dba_user;
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Permissions Inheritance — Critical for Operational Pipelines
|
|
236
|
+
|
|
237
|
+
If a **view or macro in database B** references an auth object in **database A**, then
|
|
238
|
+
**database B must have `EXECUTE`** — not just the user running the query.
|
|
239
|
+
|
|
240
|
+
```sql
|
|
241
|
+
-- Works in dev (user has EXECUTE) but the operational view will fail without this:
|
|
242
|
+
GRANT EXECUTE ON credentials_db.my_auth TO operational_db;
|
|
243
|
+
-- ^^^^^^^^^^^^^^
|
|
244
|
+
-- Grant to the DATABASE, not just the user
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Rule of thumb:** store auth objects in a dedicated credentials database, grant `EXECUTE`
|
|
248
|
+
to every database that references them, and grant to roles rather than individual users.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## DROP AUTHORIZATION
|
|
253
|
+
|
|
254
|
+
```sql
|
|
255
|
+
DROP AUTHORIZATION [DatabaseName.]authorization_name;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
> Dropping an auth object immediately breaks any query, view, or procedure that references it.
|
|
259
|
+
> Prefer `REPLACE AUTHORIZATION` for credential rotation.
|
{tdsql_mcp-1.4.3 → tdsql_mcp-1.4.5}/skills/teradata-sql-analytics/syntax/bit-byte-functions.md
RENAMED
|
@@ -37,16 +37,25 @@ Teradata uses a **big-endian** model. The most significant byte is on the left;
|
|
|
37
37
|
|
|
38
38
|
## Mismatched-Length Operands (BITAND / BITOR / BITXOR only)
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
The padding direction depends on the operand types:
|
|
41
|
+
|
|
42
|
+
- **Numeric target + shorter hex mask:** the mask is **right-padded** with zeros, so it acts on the **leading (upper) bytes**.
|
|
43
|
+
- **Two BYTE/VARBYTE operands of different lengths:** aligned on the **LSB**; the shorter is **left-padded**.
|
|
44
|
+
|
|
45
|
+
Always write hex masks at full width to avoid ambiguity:
|
|
41
46
|
|
|
42
47
|
```sql
|
|
43
|
-
-- 'FFFF'XB
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
--
|
|
48
|
+
-- Short mask is RIGHT-padded: 'FFFF'XB acts as 'FFFF0000'XB → upper two bytes
|
|
49
|
+
SELECT BITAND(287454020, 'FFFF'XB); -- 287440896 = 0x11220000 (the UPPER two bytes)
|
|
50
|
+
|
|
51
|
+
-- Full-width mask: targets the lower two bytes as intended
|
|
52
|
+
SELECT BITAND(287454020, '0000FFFF'XB); -- 13124 = 0x3344
|
|
53
|
+
|
|
54
|
+
-- Two BYTE/VARBYTE operands: aligned on LSB (shorter is left-padded)
|
|
55
|
+
SELECT BITAND('0F0F'XB, 'FF'XB); -- '000F'XB
|
|
47
56
|
```
|
|
48
57
|
|
|
49
|
-
>
|
|
58
|
+
> This applies to BITAND, BITOR, and BITXOR. Hex literals are always right-padded when extended to a required size (see above) — the same direction as the numeric+mask case.
|
|
50
59
|
|
|
51
60
|
---
|
|
52
61
|
|
|
@@ -104,9 +113,9 @@ SELECT BITAND(flags_col, BITNOT(CAST(8 AS INTEGER))) AS flags_without_bit3 FROM
|
|
|
104
113
|
-- Toggle a bit (XOR with the bit mask)
|
|
105
114
|
SELECT BITXOR(flags_col, 8) AS toggled FROM db.t;
|
|
106
115
|
|
|
107
|
-
-- Mask lower 2 bytes of an INTEGER
|
|
108
|
-
SELECT BITAND(some_int_col, '
|
|
109
|
-
-- 'FFFF'XB
|
|
116
|
+
-- Mask lower 2 bytes of an INTEGER — use a full-width mask; short mask is right-padded
|
|
117
|
+
SELECT BITAND(some_int_col, '0000FFFF'XB) AS lower_two_bytes FROM db.t;
|
|
118
|
+
-- 'FFFF'XB alone would act as '0000FFFF'XB is NOT correct: it acts as 'FFFF0000'XB (upper bytes)
|
|
110
119
|
```
|
|
111
120
|
|
|
112
121
|
---
|
|
@@ -156,10 +165,10 @@ SELECT SUBBITSTR(20, 2, 3);
|
|
|
156
165
|
-- Bits at positions 2,3,4 = 101 → right-justified in VARBYTE(1) = 00000101 = 5
|
|
157
166
|
|
|
158
167
|
-- Extract 8 bits starting at bit 4 from an INTEGER
|
|
159
|
-
SELECT SUBBITSTR(some_int_col, 4, 8) FROM db.t; --
|
|
168
|
+
SELECT SUBBITSTR(some_int_col, 4, 8) FROM db.t; -- value is 1 byte; declared type is VARBYTE(4) for INTEGER input
|
|
160
169
|
|
|
161
|
-
-- Extract 12 bits —
|
|
162
|
-
SELECT SUBBITSTR(some_int_col, 8, 12) FROM db.t; --
|
|
170
|
+
-- Extract 12 bits — value is 2 bytes, right-justified
|
|
171
|
+
SELECT SUBBITSTR(some_int_col, 8, 12) FROM db.t; -- declared VARBYTE(4); value is 2 bytes right-justified
|
|
163
172
|
```
|
|
164
173
|
|
|
165
174
|
> **Output size:** always rounded up to the next byte boundary. 3 bits requested → 1-byte VARBYTE. 9 bits requested → 2-byte VARBYTE. Excess bits are zero-filled on the left.
|
|
@@ -217,8 +226,8 @@ SELECT ROTATERIGHT(4, 4); -- 00000100 rotated right 4 = 01000000 = 64 (wrapp
|
|
|
217
226
|
SELECT TO_BYTE(23); -- BYTEINT 23 → BYTE(1) = '17'XB
|
|
218
227
|
SELECT TO_BYTE(287454020); -- INTEGER → BYTE(4) = '11223344'XB
|
|
219
228
|
|
|
220
|
-
-- Useful for inspecting the hex value of a numeric result
|
|
221
|
-
SELECT TO_BYTE(CAST(BITAND(some_col, '
|
|
229
|
+
-- Useful for inspecting the hex value of a numeric result; use a full-width mask
|
|
230
|
+
SELECT TO_BYTE(CAST(BITAND(some_col, '0000FFFF'XB) AS INTEGER)) FROM db.t;
|
|
222
231
|
```
|
|
223
232
|
|
|
224
233
|
| Input type | Output type |
|
|
@@ -234,7 +243,8 @@ SELECT TO_BYTE(CAST(BITAND(some_col, 'FFFF'XB) AS INTEGER)) FROM db.t;
|
|
|
234
243
|
|
|
235
244
|
- **All functions are Teradata-specific** — there are no ANSI SQL equivalents. Standard SQL has no bitwise function syntax; do not use `&`, `|`, `^`, `~` operators.
|
|
236
245
|
- **Signed integer overflow:** shifting or rotating a bit into the MSB (Bit 7/15/31/63) makes the result negative — all integers in Vantage are signed. This is expected behavior, not an error.
|
|
237
|
-
- **UDF implicit type conversion rules** are stricter than normal Vantage rules.
|
|
246
|
+
- **UDF implicit type conversion rules** are stricter than normal Vantage rules. A numeric mask may be **narrower** than the target (`BITAND(CAST(255 AS INTEGER), 8)` works) but not **wider** — a wider mask fails with error 9881 (`BITAND(23, CAST(20 AS INTEGER))` where 23 is BYTEINT and the mask is INTEGER). CAST the target to the wider type first: `BITAND(CAST(some_col AS INTEGER), '0000FFFF'XB)`.
|
|
238
247
|
- **`TD_SYSFNLIB.` prefix** is optional but can be included for clarity: `TD_SYSFNLIB.BITAND(...)`.
|
|
239
248
|
- **VARBYTE max size** for all functions is 8192 bytes.
|
|
240
249
|
- **DECIMAL inputs to BITAND** are implicitly converted to `NUMBER(38,0)`. BITNOT does not support DECIMAL/NUMBER.
|
|
250
|
+
- **VARBYTE results cannot be cast to a number.** `CAST(SUBBITSTR(...) AS INTEGER)` fails with error 3532 ("Conversion between BYTE data and other types is illegal"). Compare VARBYTE results as bytes; `BITAND` with a numeric target returns INTEGER, which can be cast.
|