pypika
pypika copied to clipboard
Parameter with_namespace in _set_sql is always False
In readme of updating data shows
The syntax for joining tables is the same as when selecting data
customers, profiles = Tables('customers', 'profiles')
Query.update(customers)
.join(profiles).on(profiles.customer_id == customers.id)
.set(customers.lname, profiles.lname)
UPDATE "customers"
JOIN "profiles" ON "profiles"."customer_id"="customers"."id"
SET "customers"."lname"="profiles"."lname"
But actually I got
UPDATE `customers`
JOIN `profiles` ON `profiles`.`customer_id`=`customers`.`id`
SET `lname`=`profiles`.`lname`
And I found parameter "with_namespace" was set to "False" in _set_sql() forcibly
# In pypika/queries.py at line 1527
def _set_sql(self, **kwargs: Any) -> str:
return " SET {set}".format(
set=",".join(
"{field}={value}".format(
field=field.get_sql(**dict(kwargs, with_namespace=False)), value=value.get_sql(**kwargs)
)
for field, value in self._updates
)
)
Facing the same issue!
with_namespace=False
was added in https://github.com/kayak/pypika/pull/374
It raises "COLUMN_NAME
is ambiguous" exception when we join the tables which has same column names and we want to update one.