laravel code:
$allUsers=DB::select('call getUsersCount()');
errror:
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "call" LINE 1: call getUsersCount() ^ (SQL: call getUsersCount()) (Bindings: array ( ))
function in postgress:
CREATE OR REPLACE FUNCTION public."getUsersCount"()
RETURNS bigint AS
$BODY$
SELECT count(*) FROM users;
$BODY$
LANGUAGE sql VOLATILE
COST 100;
ALTER FUNCTION public."getUsersCount"()
OWNER TO postgres;
So what is the best way to call the Postgres functions from laravel?
I don't want to convert this to like table calling. it should be like a stored procedures.
To call the Postgres functions from Laravel controller:
use the following method
$allUsersCount=DB::select('SELECT public."getUsersCount"()');
To call the Postgres functions from Laravel controller:
use the following method
$allUsersCount=DB::select('SELECT * from public.getUsersCount()');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.