pypika icon indicating copy to clipboard operation
pypika copied to clipboard

Parameter with_namespace in _set_sql is always False

Open cattybaby723 opened this issue 2 years ago • 1 comments

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
            )
        )

cattybaby723 avatar Mar 14 '22 05:03 cattybaby723

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.

pruthvi145 avatar Mar 23 '22 11:03 pruthvi145