schemas/_regproc_bss.postgres.sql
branchstable
changeset 5013 ad91f93bbb93
parent 5012 9c4ea944ecf9
child 5014 96bb4e7e3348
equal deleted inserted replaced
5012:9c4ea944ecf9 5013:ad91f93bbb93
     1 /* -*- sql -*-
       
     2 
       
     3    postgres specific registered procedures for the Bytes File System storage,
       
     4    require the plpythonu language installed
       
     5 
       
     6 */
       
     7 
       
     8 
       
     9 CREATE OR REPLACE FUNCTION _fsopen(bytea) RETURNS bytea AS $$
       
    10     fpath = args[0]
       
    11     if fpath:
       
    12         try:
       
    13             data = file(fpath, 'rb').read()
       
    14             #/* XXX due to plpython bug we have to replace some characters... */
       
    15             return data.replace("\\", r"\134").replace("\000", r"\000").replace("'", r"\047") #'
       
    16         except Exception, ex:
       
    17             plpy.warning('failed to get content for %s: %s', fpath, ex)
       
    18     return None
       
    19 $$ LANGUAGE plpythonu
       
    20 /* WITH(ISCACHABLE) XXX does postgres handle caching of large data nicely */
       
    21 ;;
       
    22 
       
    23 /* fspath(eid, entity type, attribute) */
       
    24 CREATE OR REPLACE FUNCTION fspath(bigint, text, text) RETURNS bytea AS $$
       
    25     pkey = 'plan%s%s' % (args[1], args[2])
       
    26     try:
       
    27         plan = SD[pkey]
       
    28     except KeyError:
       
    29         #/* then prepare and cache plan to get versioned file information from a
       
    30         # version content eid */
       
    31         plan = plpy.prepare(
       
    32             'SELECT X.cw_%s FROM cw_%s as X WHERE X.cw_eid=$1' % (args[2], args[1]),
       
    33             ['bigint'])
       
    34         SD[pkey] = plan
       
    35     return plpy.execute(plan, [args[0]])[0]['cw_' + args[2]]
       
    36 $$ LANGUAGE plpythonu
       
    37 /* WITH(ISCACHABLE) XXX does postgres handle caching of large data nicely */
       
    38 ;;