How to Create Procedures in PostrgeSQL?


Hey everyone,

I am trying to create a procedure in Postgres but am having a very difficult time. I am pretty sure that procedures are known as functions in Postgres but not positive.

Anyway I want to create a procedure that allows the user to input a truck number as well as 2 dates to pull the maintenance records for that truck within those date ranges.

The select and where clauses both work on their own. So if I inputted a truck number and dates manually it would pull the data I want it to. Not I am trying to modify that to create a procedure where a user can input the numbers themselves. The example I was following had @ signs to allow the input but I am getting an error there...

create function TruckMaintLookup(@truck_num int, @maint_start date, @maint_end date)
select t.truck_num, t.maint_start, t.maint_end, t.maint_type from truck_maintenance as t
where t.truck_num = @truck_num and t.maint_start BETWEEN @maint_start and @maint_end

Error message:

ERROR: syntax error at or near "@"
LINE 1: create function TruckMaintLookup(@truck_num int, @maint_star...
********** Error **********

ERROR: syntax error at or near "@"
SQL state: 42601
Character: 34

I'm trying to reference their guide but it's not much help at all...

Thank you so much for any and all help!!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.