Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
¿Por qué Django no ajusta [] o SELECT a ARRAY en caso de usar el campo Array?

Por ejemplo, tengo una consulta como:

 Chat.objects.filter(users__contains=[user.pk]).filter(users__contained_by=mentors.values_list('pk', flat=True))

Esto se convierte en tal consulta:

 SELECT "chat_chat"."created_at", "chat_chat"."updated_at", "chat_chat"."id", "chat_chat"."users" FROM "chat_chat" WHERE ("chat_chat"."users" @> [1]::integer[] AND "chat_chat"."users" <@ (SELECT V0."id" FROM "users_user" V0 INNER JOIN "users_userrequest_mentors" V1 ON (V0."id" = V1."user_id") WHERE V1."userrequest_id" IN (SELECT U0."id" FROM "users_userrequest" U0 WHERE U0."user_id" = 1))::integer[])

Si ejecuto esta consulta, me enfrentaré al problema de la transmisión.

no se puede convertir entero a entero[]

Pero la documentación de Postgres dice que las matrices deben usarse como ARRAY[1,2,...,4]
Así que he envuelto [1] y (SELECCIONAR ...) a ARRAY como

 SELECT "chat_chat"."created_at", "chat_chat"."updated_at", "chat_chat"."id", "chat_chat"."users" FROM "chat_chat" WHERE ("chat_chat"."users" @> ARRAY[1]::integer[] AND "chat_chat"."users" <@ ARRAY(SELECT V0."id" FROM "users_user" V0 INNER JOIN "users_userrequest_mentors" V1 ON (V0."id" = V1."user_id") WHERE V1."userrequest_id" IN (SELECT U0."id" FROM "users_userrequest" U0 WHERE U0."user_id" = 1))::integer[])

Y todo funciona bien.
Tengo curiosidad por saber por qué Django (o psycopg2) se salta este envoltorio. ¿Hay algún significado especial para tal comportamiento?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!