Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
Postgres Search Strategy

I have data that is segmented into:-

  • postcode
  • town
  • place

My aim is to construct a search function that will look for any text given using the above segmentations in order of precedence. ie. First look for postcode, then town then place

Can this be done efficiently without having to full scan postcode/town before getting on to place? I can identify that the text is a postcode using a REGEX, town and place are more difficult.

I am happy to code this as a PLPGSQL function and made some progress with a strategy along these lines:-

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 Respuestas
Responde la pregunta

0

I solved this using weightings and combining my data into a single table with columns POSTCODE, TOWN, PLACE which my data allows me to do.

I can then create an additional column tsv as:-

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

And search with:-

 WHERE (tsv @@ plainto_tsquery('SN1 3PF'))
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda