Examples | SCRIPT Table Operator | Teradata Vantage - 17.10 - Example: SCRIPT Table Operator Function - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Operators and User-Defined Functions

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Administration
Programming Reference
Publication ID
B035-1210-171K
Language
English (United States)

Create a file called helloworld.py in the /root directory with the following code:

print ('hello world!')

Install the file in the database:

DATABASE mydatabase;
CALL SYSUIF.INSTALL_FILE('helloworld',
                         'helloworld.py', 'cz!/root/helloworld.py');

Run the script:

SET SESSION SEARCHUIFDBPATH = mydatabase;
SELECT DISTINCT *
FROM SCRIPT (
	  SCRIPT_COMMAND('/opt/teradata/languages/Python/bin/python3 ./mydatabase/helloworld.py')
);

In the following example, install a script and other files, and then execute the SCRIPT table operator.

DATABASE mydb;
SET SESSION SEARCHUIFDBPATH = mydb;
CALL SYSUIF.INSTALL_FILE('my_analytics',
                         'cz!my_analytics.sh!/tmp/my_analytics.sh');
CALL SYSUIF.INSTALL_FILE('my_model',
            'cz!my_model.model!/tmp/my_model.sh');
CALL SYSUIF.INSTALL_FILE('my_data',
                         'cz!my_data.dat!/tmp/my_data.dat');
SELECT * FROM SCRIPT( ON data_table
		SCRIPT_COMMAND('./mydb/my_analytics.sh –mymodel ./mydb/my_model.model –myadditionaldata ./mydb/my_data.dat')
		RETURNS('*','score varchar(10)');