I am trying to put each attribute from the dictionary into a backstick to create a query out of it, however all I got is that it starts with a backstick and finish with a backstick despite all my efforts
base_datatypes = [
{"datatype": 1, "data_type_name": "SomeValue"},
{"datatype": 2, "data_type_name": "DateTime"},
]
datatype_attributes_dict = {
"DateTime": "'Year','Month','Day'"
}
created_base_attributes = [
"attribute_DateTimeTable",
"attribute_SomeDictionary"
]
select_clause = "SELECT COALESCE(t1.sys_id, t2.sys_id) AS PK"
for i, view in enumerate(created_base_attributes, start=1):
data_type_name = next((item["data_type_name"] for item in base_datatypes if f"attribute_{item['data_type_name'].lower()}" == view), None)
if data_type_name:
attributes = datatype_attributes_dict.get(data_type_name, "")
if attributes:
columns = [f"`{attr.strip()}`" for attr in attributes.replace("'", "").split(",")]
select_clause += ", " + ", ".join(columns)
print(select_clause)
I got output like (despite SELECT COALESCE (..))
like ”Year'
‘
New contributor
Data_engineer_noobie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.