0

I have some postgresql functions that I run in the form:

SELECT * FROM pgfunction(1,2,3);

This enables me to filter / order / group the results:

SELECT * FROM pgfunction(1,2,3) WHERE value > 10;

How could I pass the parameters to the postgresql function in laravel using prepared statements in order to filter the results in laravel. Example:

DB::table('pgfunction',array(1,2,3))->where('value','>','10');

Is this possible?

1 Answer 1

2

DB::raw will create a raw SQL string, but not use it as a query. You may need to use a DB::select() to run a "raw sql" query.

$fnc = sprintf("pgfunction(%s)", implode(',', array(1,2,3));

DB::select()->from(DB::raw($fnc))->where('value', '>', 10);

Note: This is untested on my end. Hope it helps. See the docs on using Raw Expressions for more information on using that.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I have mixed "DB::RAW" and "DB::table". I have fixed this typo in the question. The idea was to use this function as a table exactly as postgresql does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.