使用psycopg2引擎用django編寫應用程序。似乎並不總是想引用我的字符串。這裏是一個測試用例:爲什麼這些字符串不會被psycopg2引用以進行查詢?
>>> from pypvs.search.models import Addr2zip
>>> kwargs = {
... 'street_name__iexact': 'Common Ground',
... 'state_id__iexact': 'MT',
... }
>>> addrMatch = Addr2zip.objects.extra(
... where = ['ctystate.zip5 = addr2zip.zip5 AND ctystate.city_name = \'%s\'' % 'Philipsburg'],
... tables = ['ctystate', 'addr2zip']
...).filter(**kwargs).order_by('zip5', 'street_name', 'primary_address_low', 'secondary_address_low')
>>> print addrMatch.query
SELECT "addr2zip"."addr2zip_id", "addr2zip"."zip5", "addr2zip"."zip4_low", "addr2zip"."zip4_high", "addr2zip"."street_direction", "addr2zip"."street_name", "addr2zip"."street_suffix", "addr2zip"."street_post_direction", "addr2zip"."primary_address_low", "addr2zip"."primary_address_high", "addr2zip"."primary_address_parity", "addr2zip"."secondary_address", "addr2zip"."secondary_address_low", "addr2zip"."secondary_address_high", "addr2zip"."secondary_address_parity", "addr2zip"."state_id", "addr2zip"."county_code", "addr2zip"."municipality_key", "addr2zip"."urbanization_key", "addr2zip"."record_type" FROM "addr2zip" , "ctystate" WHERE (ctystate.zip5 = addr2zip.zip5 AND ctystate.city_name = Philipsburg AND UPPER("addr2zip"."state_id"::text) = UPPER(MT) AND UPPER("addr2zip"."street_name"::text) = UPPER(Common Ground)) ORDER BY "addr2zip"."zip5" ASC, "addr2zip"."street_name" ASC, "addr2zip"."primary_address_low" ASC, "addr2zip"."secondary_address_low" ASC
什麼原因導致這些字符串不被引用?例如,「共同點」:
AND UPPER("addr2zip"."street_name"::text) = UPPER(Common Ground)
不知道問題出在我的實現,psycopg2,或者Django的ORM。我會很感激任何想法。
我得到的一個。但請參閱我在「street_name」原始帖子中使用的示例。 – 2010-11-24 22:56:19