Sandy
Sandy
MModular
Created by Sandy on 2/16/2024 in #questions
String to StringLiteral
Any ideas how I might convert a String to a StringLiteral? I'm trying to interact with a postgres database and if I don't have the parameters as a StringLiteral it doesn't want to work. Not sure how I might get around this. For example the following works if you pass the name as a StringLiteral but not as a String and I don't know how I might convert a String to a StringLiteral for the purposes of using this function: fn get_name(cursor: PythonObject, name: StringLiteral) raises -> PythonObject: let np = Python.import_module("numpy") var name_array = np.array(()) let sql = """ SELECT * FROM customer WHERE name = %s """ let data = (name,)
try: cursor.execute(sql, data) var names = cursor.fetchall() name_array = names except Exception: print("Error: ", Exception) return name_array
5 replies