1

from a lambda function in AWS I am calling a stored procedure in Snowflake. I run python code and use sqlalchemy and snowflake.sqlalchemy modules to call the snowflake stored proc. the stored procedure queries a table with one row and one column, does a simple calculation and returns a single value. The code looks like this:

result=connection.execute('CALL TEST_GET_PARAMS(8,8);')
sql='select * from CALCRESULT;'
rows = result.fetchone()
print(rows)
print (type(rows))

the return looks like this:

(160.0,)
<class 'sqlalchemy.engine.result.RowProxy'>

However, I want to value to be an int value without the ( ) and ,

I am assuming my problem is in the use of fetchone and then how take the first column out of the result, but I don't know how to do it.

Any suggestions?

0

2 Answers 2

1

The RowProxy object returned by result.fetchone() permits dictionary-style access of columns within.

For example, if the lone column inside your CALCRESULT table is called COLUMN_NAME then you can use this to retrieve just its value:

>>> […]
>>> row = result.fetchone()

>>> value = row["COLUMN_NAME"]
>>> print(value)
160.0
Sign up to request clarification or add additional context in comments.

Comments

0

You can try using fetchmany(size=1) inplace of fetchone().And define the size limit according to your column requirement.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.