0

I am trying to use teradatasql and the sample code given for FastExportTable is throwing error for me.

Code:

#!~/miniconda3/bin/python
# This sample program demonstrates how to FastExport rows from a table.

import teradatasql

with teradatasql.connect (host='TD_DB_IP', user='db_user_name', password='db_password', database='teradata_db_name') as con:
    with con.cursor () as cur:
        with con.cursor () as cur2:
            sTableName = "FastExportTable"
            try:
                sRequest = "DROP TABLE " + sTableName
                print (sRequest)
                cur.execute (sRequest)
            except Exception as ex:
                print ("Ignoring", str (ex).split ("\n") [0])

            sRequest = "CREATE TABLE " + sTableName + " (c1 INTEGER NOT NULL, c2 VARCHAR(10))"
            print (sRequest)
            cur.execute (sRequest)

            try:
                sInsert = "INSERT INTO " + sTableName + " VALUES (?, ?)"
                print (sInsert)
                cur.execute (sInsert, [
                    [1, None],
                    [2, "abc"],
                    [3, "def"],
                    [4, "mno"],
                    [5, None],
                    [6, "pqr"],
                    [7, "uvw"],
                    [8, "xyz"],
                    [9, None],
                ])

                sSelect = "{fn teradata_try_fastexport}SELECT * FROM " + sTableName
                print (sSelect)
                cur.execute (sSelect)
                [ print (row) for row in sorted (cur.fetchall ()) ]

                sRequest = "{fn teradata_nativesql}{fn teradata_get_warnings}" + sSelect
                print (sRequest)
                cur2.execute (sRequest)
                [ print (row) for row in cur2.fetchall () ]

                sRequest = "{fn teradata_nativesql}{fn teradata_get_errors}" + sSelect
                print (sRequest)
                cur2.execute (sRequest)
                [ print (row) for row in cur2.fetchall () ]

                sRequest = "{fn teradata_nativesql}{fn teradata_logon_sequence_number}" + sSelect
                print (sRequest)
                cur2.execute (sRequest)
                [ print (row) for row in cur2.fetchall () ]

            finally:
                sRequest = "DROP TABLE " + sTableName
                print (sRequest)
                cur.execute (sRequest)

Error:

Traceback (most recent call last):
  File "./sample_tdsql_fastexporttable.py", line 38, in <module>
    cur.execute (sSelect)
  File "~/miniconda3/lib/python3.6/site-packages/teradatasql/__init__.py", line 649, in execute
    self.executemany (sOperation, None, ignoreErrors)
  File "~/miniconda3/lib/python3.6/site-packages/teradatasql/__init__.py", line 896, in executemany
    raise OperationalError (sErr)
teradatasql.OperationalError: [Version 16.20.0.62] [Session 590874] [Teradata Database] [Error 3706] Syntax error: expected something between the beginning of the request and the word 'teradata_try_fastexportSELECT'.

Only change I did in the sample program provided on github for this module is add database='teradata_db_name'. If I remove database='teradata_db_name' and run same code I get error on line 19: teradatasql.OperationalError: [Version 16.20.0.62] [Session 590869] [Teradata Database] [Error 2644] No more room in database SVC_DEV_XDW_VANTAGE..

We are using Python 3.6.0 :: Continuum Analytics, Inc.

Has anyone got same error? What am I missing here? Any information to resolve this is greatly appreciated.

FlyingTeller
  • 17,638
  • 3
  • 38
  • 53
300
  • 965
  • 1
  • 14
  • 53
  • 1
    Upgrade your driver: teradatasql 16.20.0.62 does not have fastexport support; that was added in 17.0.0.7 – Fred Dec 16 '21 at 18:19

1 Answers1

0

To resolve this, upgrade to teradatasql 17.10.0.6 - February 4, 2022 or later... as of this writing "pip install teradatasql -- upgrade" will get you version 17.20.0.0

teradatasql is documented here : https://pypi.org/project/teradatasql/ and "GOSQL-73 Write CSV files" shows the 17.10.0.6 update.

If you are running Jupyter, make sure you restart your kernel or the error will continue until you restart.

After the upgrade, this python instruction ran fine.

cur.execute("{fn teradata_write_csv(mycsvfilename.csv)}select * dbc.dbcinfo;")

FastExport works also:

cur.execute("{fn teradata_try_fastexport}{fn teradata_write_csv(mycsvfilename.csv)}select * from dbc.dbcinfo;")

dbc.dbcinfo really isn't worth the overhead of fast export, but the example will work for everyone.