Revision 2952
Added by Aaron Marcuse-Kubitza over 12 years ago
py_functions.sql | ||
---|---|---|
83 | 83 |
-- |
84 | 84 |
|
85 | 85 |
CREATE FUNCTION "_namePart"() RETURNS trigger |
86 |
LANGUAGE plpgsql IMMUTABLE |
|
87 |
AS $$ |
|
88 |
BEGIN |
|
89 |
new.result := py_functions."_namePart"(new.first, new.middle, new.last); |
|
90 |
RETURN new; |
|
91 |
END; |
|
92 |
$$; |
|
93 |
|
|
94 |
|
|
95 |
ALTER FUNCTION py_functions."_namePart"() OWNER TO bien; |
|
96 |
|
|
97 |
-- |
|
98 |
-- Name: _namePart(text, text, text); Type: FUNCTION; Schema: py_functions; Owner: bien |
|
99 |
-- |
|
100 |
|
|
101 |
CREATE FUNCTION "_namePart"(first text DEFAULT NULL::text, middle text DEFAULT NULL::text, last text DEFAULT NULL::text) RETURNS text |
|
86 | 102 |
LANGUAGE plpythonu IMMUTABLE |
87 | 103 |
AS $$ |
88 |
new = TD['new']
|
|
104 |
params = dict(first=first, middle=middle, last=last)
|
|
89 | 105 |
|
90 | 106 |
_name_parts_slices_items = [ |
91 | 107 |
('first', slice(None, 1)), |
... | ... | |
103 | 119 |
return ' '.join(parts) |
104 | 120 |
|
105 | 121 |
out_items = [] |
106 |
for part, value in new.iteritems():
|
|
122 |
for part, value in params.iteritems():
|
|
107 | 123 |
if value == None: continue |
108 | 124 |
|
109 | 125 |
try: slice_ = name_parts_slices[part] |
110 | 126 |
except KeyError: pass # a non-value column |
111 | 127 |
else: out_items.append((part, ' '.join(value.split(' ')[slice_]))) |
112 | 128 |
|
113 |
new['result'] = _name(out_items) |
|
114 |
|
|
115 |
return 'MODIFY' |
|
129 |
return _name(out_items) |
|
116 | 130 |
$$; |
117 | 131 |
|
118 | 132 |
|
119 |
ALTER FUNCTION py_functions."_namePart"() OWNER TO bien; |
|
133 |
ALTER FUNCTION py_functions."_namePart"(first text, middle text, last text) OWNER TO bien;
|
|
120 | 134 |
|
121 | 135 |
-- |
122 | 136 |
-- Name: parse_date_range(text); Type: FUNCTION; Schema: py_functions; Owner: bien |
... | ... | |
266 | 280 |
-- Name: _namePart; Type: TRIGGER; Schema: py_functions; Owner: bien |
267 | 281 |
-- |
268 | 282 |
|
269 |
CREATE TRIGGER "_namePart" BEFORE INSERT OR UPDATE ON "_namePart" FOR EACH ROW EXECUTE PROCEDURE "_namePart"(); |
|
283 |
CREATE TRIGGER "_namePart" BEFORE INSERT OR UPDATE ON "_namePart" FOR EACH ROW EXECUTE PROCEDURE py_functions."_namePart"();
|
|
270 | 284 |
|
271 | 285 |
|
272 | 286 |
-- |
Also available in: Unified diff
schemas/py_functions.sql: Added plain function _namePart() and use it in trigger function _namePart()