-1

I'm using the teradatasql python module and i'm unable to find in documentation on how to pass named parameters into the cursor.execute()

i have stored procedure which takes IN parameter , but in teradatasql i dont see option to pass column name. is there any way to do this?

here is some snippet of my PROC which takes IN parameters

(
        IN transId VARCHAR(50),
        IN name VARCHAR(50),
        IN  add VARCHAR(50),
        IN  zip VARCHAR(50),
        IN  area VARCHAR(50)
    )

code

with teradatasql.connect ('{"host":"whomooz","user":"guest","password":"please"}') as con:
    with con.cursor () as cur:
        cur_execute (cur, "{call examplestoredproc (?, ?)}", [10, 7]) # bound parameter values

def cur_execute (cur, sSQL, params=None):
    print ()
    print ("cur.execute", sSQL, "bound values", params)
    cur.execute (sSQL, params)
user1591156
  • 1,945
  • 4
  • 18
  • 31
  • No error message? If you really want to pass a *column name* you need to switch to Dynamic SQL in your SP – dnoeth Oct 28 '21 at 08:32
  • @dnoeth Yes, no error message just returns the zero records. So there is no otherway to pass column name using ```teradatasql```? – user1591156 Oct 28 '21 at 12:52
  • What are you trying to do with the "column name"? Show the relevant bits of your proc. Nothing in your parameters you're showing seem related to that. – Andrew Oct 28 '21 at 14:03
  • Only positional parameters - indicated by ? - are supported in the request and not named parameters like `zip='12345'`. If you want to pass values for, say, only the second and fourth parameter than you need placeholders - possibly `None` on the Python side. – Fred Oct 28 '21 at 14:17
  • @Fred, so by looking my storedprocedure example in post. this how my request is going ```cur.execute {call examplestoredproc (?,?, ?, ?, ?,?,?)} bound values ['1233', '2222', 'Test', 'Test1', None, 'I', 'test2']``` .. and its returning Zero records .. how i can make sure each value is in order of matching with my storedprocedure ? – user1591156 Oct 28 '21 at 15:02
  • The match is strictly positional - order in the values list passed to `execute` method corresponds to order of parameter markers in the request, and order of parameters in the CALL corresponds to order in the DEFINE PROCEDURE. – Fred Oct 28 '21 at 22:34

1 Answers1

0

I'm using the teradatasql python module and i'm unable to find in documentation on how to pass named parameters into the cursor.execute()

The Teradata Database does not support binding stored procedure argument values by name. Therefore, the teradatasql driver cannot support that either.

You must specify question-mark parameter markers in your call to the stored procedure, and you must specify unnamed stored procedure argument values that are bound by position to the question-mark parameter markers.

Tom Nolan
  • 394
  • 2
  • 5