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
Post a Comment