php - Get max or min of parameter to row value postgres -


for parameterized postgresql query, how can return either value in row or parameter provided.

i have table (we call foo) 3 columns: id, maximum, minimum

i want select rows max , min have ceiling or floor provide them. directly in postgresql able select this:

select    id,    greatest(minimum, 5),    least(maximum, 10) foo 

so return values between 5 , 10 each row.

however when converting use in php code:

$floor = 5; $ceiling = 10; $query = 'select id, greatest(minimum, $2), least(maximum, $1) foo'; $parameters = [ $ceiling, $floor]; $result = pg_query_params($query, $parameters); 

this doesn't work because parameters need in where clause of query. how write query able pass in parameters properly?

you use heredoc:

$floor = 5; $ceiling = 10;  $query = <<<sql select      id,      greatest(minimum, $floor),     least(maximum, $ceiling)      foo sql;  $result = pg_query_params($query); 

for reference, see:


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -