We have learned how to take data from Teradata, pass it to a script and get output. Is there an easy way to store this output in a table? Sure, there is. We can use the following pattern:
-- We inform Teradata to create a symbolic link from the UIF directory to ./sto/
SET SESSION SEARCHUIFDBPATH = sto;
-- First, create the table structure
CREATE MULTISET TABLE url_params
(param_key varchar(512), param_value varchar(512))
NO PRIMARY INDEX;
-- Then insert the SCRIPT results
INSERT INTO url_params
SELECT *
FROM SCRIPT(
ON(SELECT url FROM urls)
SCRIPT_COMMAND('python3 ./sto/urlparser.py')
RETURNS ('param_key varchar(512)', 'param_value varchar(512)'));
Now, let's inspect the contents of url_params table:
SELECT * FROM url_params;
You should see the following output:
param_key |param_value
------------+-----------------------------------------------------
q |NYSE:TDC
_trksid |p2050601.m570.l1313.TR0.TRC0.H0.Xteradata merchandise
search_query|teradata commercial
_nkw |teradata merchandise
sm |3
_sacat |0
mylist |1
_from |R40
mylist |2
mylist |...testing