Skip to content

Difference in behavior between a Field and an Attribute when used directly in a class #835

@PedroH183

Description

@PedroH183

Below, I show a simple example. The generated SQL has a difference in the "" around the field, but in the docs it is showed as equivalent.

What is the proper use case for these features ?

from pypika import Table, Query, Field, Parameter

shops = Table("shops")

first_query = Query.from_(shops).select(
    Field(shops.id, 'identification')
).where(
    shops.id == Parameter("%(shop_id)s")
)
# SELECT ""id"" "identification" FROM "shops" WHERE "id"=%(shop_id)s

second_query = Query.from_(shops).select(
    shops.id.as_('identification')
).where(
    shops.id == Parameter("%(shop_id)s")
)
# SELECT "id" "identification" FROM "shops" WHERE "id"='%(shop_id)s'

assert first_query == second_query
print(first_query, second_query)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions