MemFire Cloud应用开发:如何使用python 进行条件查询
-
1、创建一张数据表
CREATE TABLE "public"."tb_user" ( "f_id" SERIAL, "f_name" VARCHAR NOT NULL, CONSTRAINT "tb_user_pkey" PRIMARY KEY ("f_id") ); INSERT INTO "public"."tb_user" ("f_id", "f_name") VALUES ('1', 'aaaa'); INSERT INTO "public"."tb_user" ("f_id", "f_name") VALUES ('2', 'bbbb');
2、创建一个函数
CREATE OR REPLACE FUNCTION get_users(num1 text, num2 text) RETURNS TABLE (id INT, name VARCHAR) AS $$ DECLARE value INTEGER; BEGIN value := CAST(num1 AS INTEGER); RETURN QUERY SELECT f_id, f_name FROM tb_user WHERE f_id = value OR f_name = num2; END; $$ LANGUAGE plpgsql;
调用函数查询结果如下:
3、使用rpc来调用函数
from supabase import create_client, Client supabase: Client = create_client("url", "anon_key") result = supabase.rpc("get_users", {"num1": 1, "num2": "bbbb"}).execute() print(result)
运行即可返回结果