-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathAGKRInsertSelect.ts
40 lines (32 loc) · 1.59 KB
/
AGKRInsertSelect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2023 by Teradata Corporation. All rights reserved.
// This sample program demonstrates Insert/Select with Auto-Generated Key Retrieval (AGKR).
// @ts-ignore
import * as teradatasql from "teradatasql";
const con: teradatasql.TeradataConnection = teradatasql.connect({ host: "whomooz", user: "guest", password: "please" });
try {
const cur: teradatasql.TeradataCursor = con.cursor();
try {
const sTableName: string = "agkrdemo";
cur.execute("drop table " + sTableName, undefined, 3807);
cur.execute("create table " + sTableName + " (c1 integer generated by default as identity, c2 varchar(100))");
try {
console.log("Using AGKR option C to return identity column values only");
cur.execute("{fn teradata_agkr(C)}insert into " + sTableName + " (c2) select InfoKey from DBC.DBCInfo");
console.log("All identity column values are returned in one result set");
console.log(cur.fetchall());
console.log("Using AGKR option R to return entire inserted rows");
cur.execute("{fn teradata_agkr(R)}insert into " + sTableName + " (c2) select InfoData from DBC.DBCInfo");
console.log("All inserted rows are returned in one result set");
console.log(cur.fetchall());
console.log("Final contents of table");
cur.execute("select * from " + sTableName + " order by 1");
console.log(cur.fetchall());
} finally {
cur.execute("drop table " + sTableName);
}
} finally {
cur.close();
}
} finally {
con.close();
}