【发布时间】:2023-04-01 16:12:01
【问题描述】:
我正在创建一个用于搜索栏和过滤器的函数。以下是我的代码:
CREATE OR REPLACE FUNCTION functions.search_function(
student text[] DEFAULT NULL,
professors text[] DEFAULT NULL)
RETURNS TABLE(
student text,
student_id int,
professor_name text,
subject text,
subject_time timestamp without time zone,
room_number int,
building text)
LANGUAGE 'sql'
AS $BODY$
SELECT
student,
student_id,
professor_name,
subject,
subject_timetime,
room_number,
building
FROM "school_records_table"
WHERE (LOWER("student") = any($1) OR $1 IS NULL)
AND ((LOWER("professor_name") =any($2)) OR $2 IS NULL)
$BODY$;
是否可以在代码中的任何位置插入以改变 SELECT 语句中的列?例如,我只想选择学生、教授姓名、学科和房间号?它将用作过滤器。如果是,我怎样才能将它插入我的函数中?非常感谢
【问题讨论】:
标签: sql postgresql function pgadmin