1 -- SQL statement to create a stored function, computecurrentlocation(csid),
2 -- in a PostgreSQL database.
4 -- The SQL statement to drop (remove) this function from that database,
5 -- at any point following its creation, is:
7 -- DROP FUNCTION computecurrentlocation(character varying)
8 CREATE OR REPLACE FUNCTION computecurrentlocation(character varying) RETURNS character varying
9 AS 'select m.currentlocation as computedcurrentlocation
10 from movements_common m,
14 collectionobjects_common c,
17 and r.subjectcsid=h1.name
18 and r.subjectdocumenttype=''Movement''
19 and r.objectdocumenttype=''CollectionObject''
20 and r.objectcsid=h2.name
23 and misc.lifecyclestate <> ''deleted''
24 and m.currentlocation is not null
25 and m.locationdate is not null
27 order by m.locationdate desc,row_number() over(order by locationdate)
31 RETURNS NULL ON NULL INPUT;