Sample query
users_id_query = '''
SELECT CAST(user_id as char) as user_id FROM users_table;
'''
Execute the above query in Python.
users_ids = execute_query('my_database', users_id_query)
Why do you want the result to look like "111,222,333":
users_result = [str(x['user_id']) for x in users_ids['rows']]
users_ids_string = ','.join(users_result)
The users_ids_string is nicely filled with comma-separated values that you want.
Sample SQL
users_login_query = '''
SELECT count(0) FROM login_log_table where user_id in (user_ids_string)
'''
"User_ids_string" is the parameter to replace with the actual value next.
entry_users_ids = execute_query('my_database', users_login_query.replace('user_ids_string', entry_users_ids_string))
Replace the value at the same time while specifying the execution destination.
Recommended Posts