]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8fc32eb01796c663b659de6b693871722488f40e
[tmp/jakarta-migration.git] /
1 -- SQL statement to create a stored function, computecurrentlocation(csid),
2 -- in a PostgreSQL database.
3 --
4 -- The SQL statement to drop (remove) this function from that database,
5 -- at any point following its creation, is:
6 --
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, 
11 hierarchy h1, 
12 relations_common r, 
13 hierarchy h2, 
14 collectionobjects_common c, 
15 misc misc 
16 where m.id=h1.id 
17 and r.subjectcsid=h1.name 
18 and r.subjectdocumenttype=''Movement'' 
19 and r.objectdocumenttype=''CollectionObject'' 
20 and r.objectcsid=h2.name 
21 and h2.id=c.id 
22 and misc.id=c.id 
23 and misc.lifecyclestate <> ''deleted'' 
24 and m.currentlocation is not null 
25 and m.locationdate is not null 
26 and h2.name=$1 
27 order by m.locationdate desc,row_number() over(order by locationdate) 
28 limit 1' 
29 LANGUAGE SQL
30     IMMUTABLE 
31     RETURNS NULL ON NULL INPUT;