PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Passare i parametri DOVE a PostgreSQL View?

Potresti usare una funzione di ritorno set:

create or replace function label_params(parm1 text, parm2 text)
  returns table (param_label text, param_graphics_label text)
as
$body$
  select ...
  WHERE region_label = $1 
     AND model_id = (SELECT model_id FROM models WHERE model_label = $2)
  ....
$body$
language sql;

Allora puoi fare:

select *
from label_params('foo', 'bar')

A proposito:sei sicuro di volere:

AND model_id = (SELECT model_id FROM models WHERE model_label = $2)

se model_label non è univoco (o la chiave primaria), quindi questo genererà un errore alla fine. Probabilmente vuoi:

AND model_id IN (SELECT model_id FROM models WHERE model_label = $2)