Re: LIKE a campo integer

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Herman Estaban <hermanestaban(at)gmail(dot)com>
Cc: "Crispin T(dot)" <cris(dot)emis(at)gmail(dot)com>, Hellmuth Vargas <hivs77(at)gmail(dot)com>, FORO POSTGRES <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: LIKE a campo integer
Date: 2016-06-22 13:31:12
Message-ID: 20160622133112.GA136996@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Herman Estaban escribió:

> Tengo una tabla PRD_REG con 02 campos:
>
> ID_TIP_REG INTEGER
> NOM_TIP_REG VARCHAR(25)
>
> Esta tabla tiene 14 registros y esta registrado asi:
>
> ID_TIP_REG | NOM_TIP_REG
> 1 | DETALLADO
> 2 | MARCADO
> 3 | PROGRAMADO
> 4 | CON DISEÑO
> 5 | SIN DISEÑO
> .
> .
> .
> 99 | SIN REGISTRAR
>
> He creado un funcion, que tiene un parametro (param) de tipo INTEGER, en
> esta funcion la que esta tabla PRD_REG se cruza con JOIN con otra tabla y
> en el WHERE quiero usar un LIKE ya que el usuario puede elegir cualquiera
> de los codigos de la tabla PRD_REG, como tambien todos por eso necesito el
> LIKE.
>
> Por eso utilizo esto:
> WHERE CAST(ID_TIP_REG AS CHAR) LIKE param;

Suena a mal diseño de la función.

consulta := 'select bla bla from prd_reg '
if param IS NOT NULL then
consulta := consulta || 'where id_tip_reg = ' || param
end if;
execute consulta;

Así, si le pasas un NULL a param significa "todos", pero si es un valor
específico entonces trae los registros de ese código.

Alternativamente, si quieres varios códigos, podrías usar = ANY,
select .. from prd_reg where id_tip_reg = any (1, 4, 6)

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

-
Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
Para cambiar tu suscripción:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message eduardo reyes 2016-06-22 14:37:30 Re: LIKE a campo integer
Previous Message Hellmuth Vargas 2016-06-22 04:30:32 Re: LIKE a campo integer