Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
Creating a GIN index in Django

I have created a model in Django.

class MyModel(models.Model):
    features = TextField(blank=True, default='')

There are several possible ways to store the data in the feature field. Some examples below.

  1. feature1;feature2
  2. feature1, feature2
  3. feature1,feature2

And so on. I need to create a GIN index for that field. I would probably do it in postgreSQL in the following way

CREATE INDEX features_search_idx ON "mymodel" USING gin (regexp_split_to_array("mymodel"."features", E'[,;\\s]+'));

Would it be possible to do the same thing by a migration?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yes.

  • Create an empty migration: python manage.py makemigration yourapp --empty -n pour_gin
  • Add a migrations.RunSQL() operation in the migration file.
class Migration(migrations.Migration):

    dependencies = [
        # ...
    ]
    operations = [
        migrations.RunSQL(
            sql="""CREATE INDEX features_search_idx ON "mymodel" USING gin (regexp_split_to_array("mymodel"."features", E'[,;\\s]+'));""",
            reverse_sql=migrations.RunSQL.noop,  # TODO: replace me with DROP INDEX
        ),
    ]
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda