[英]How to call the postgress function/stored procedure from laravel controller?
laravel code: laravel 代码:
$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: function 在后退:
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?那么从 laravel 调用 Postgres 函数的最佳方法是什么?
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: 要从Laravel控制器调用Postgres函数:
use the following method 使用以下方法
$allUsersCount=DB::select('SELECT public."getUsersCount"()');
To call the Postgres functions from Laravel controller:从 Laravel controller 调用 Postgres 函数:
use the following method使用以下方法
$allUsersCount=DB::select('SELECT * from public.getUsersCount()');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.