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

127
Views
Estrategia de búsqueda de Postgres

Tengo datos que están segmentados en: -

  • código postal
  • pueblo
  • lugar

Mi objetivo es construir una función de búsqueda que busque cualquier texto dado utilizando las segmentaciones anteriores en orden de precedencia. es decir. Primero busque el código postal, luego la ciudad y luego el lugar

¿Se puede hacer esto de manera eficiente sin tener que escanear por completo el código postal/ciudad antes de llegar al lugar? Puedo identificar que el texto es un código postal usando REGEX, la ciudad y el lugar son más difíciles.

Estoy feliz de codificar esto como una función PLPGSQL y progresé con una estrategia en este sentido:

 WITH POSTCODES AS ( SELECT postcode FROM postcode WHERE postcode ~* $1 ), TOWNS AS ( SELECT town FROM towns WHERE (SELECT * FROM POSTCODES LIMIT 1) IS NULL AND town ~* $1 ), PLACES AS ( SELECT place FROM places WHERE (SELECT * FROM TOWNS LIMIT 1) IS NULL AND place ~* $1 ) SELECT postcode as res FROM POSTCODE UNION ALL SELECT town as res FROM TOWNS UNION ALL SELECT place as res FROM PLACES
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Resolví esto usando ponderaciones y combinando mis datos en una sola tabla con columnas CÓDIGO POSTAL, CIUDAD, LUGAR que mis datos me permiten hacer.

Luego puedo crear una columna adicional tsv como: -

 setweight(to_tsvector(COALESCE(postcode,'')), 'A') || setweight(to_tsvector(COALESCE(town,'')) , 'B') || setweight(to_tsvector(COALESCE(place,'')) , 'C')

Y busca con:-

 WHERE (tsv @@ plainto_tsquery('SN1 3PF'))
over 4 years ago · Santiago Trujillo Report
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!