使用Python接口来进行关联查询操作
-
创建两张外键关联表,插入两条数据
CREATE TABLE "public"."tb_user" ( "f_id" SERIAL, "f_name" VARCHAR NOT NULL, CONSTRAINT "tb_user_pkey" PRIMARY KEY ("f_id") ); CREATE TABLE "public"."tb_login" ( "f_id" SERIAL, "f_date" VARCHAR NOT NULL, "f_user_id" BIGINT NOT NULL, CONSTRAINT "tb_login_pkey" PRIMARY KEY ("f_id") ); ALTER TABLE "public"."tb_login" ADD CONSTRAINT "tb_login_f_user_id_fkey" FOREIGN KEY ("f_user_id") REFERENCES "public"."tb_user" ("f_id") ON DELETE NO ACTION ON UPDATE NO ACTION; INSERT INTO "public"."tb_user" ("f_id", "f_name") VALUES ('1', 'aaaa'); INSERT INTO "public"."tb_login" ("f_id", "f_date", "f_user_id") VALUES ('1', '2022', '1');
操作样例: 其中
from supabase import create_client, Client supabase: Client = create_client("url", "key") data = supabase.table("tb_user").select( "f_id, tb_login(f_id,f_date)").eq("f_id", "1").execute() print(data)