I am trying to populate a view in PostGIS in Postgres 9.0 and in this view I want it to contain a substring based on 2 string positions. See below for my code.
CREATE OR REPLACE VIEW vw_actions AS
SELECT ls.f_table_schema, ls.f_table_name,
(SELECT substr(ls.attribute_actions_text,
strpos(ls.attribute_actions_text, 'name="')+6,
strpos(ls.attribute_actions_text, '"/>') -
strpos(ls.attribute_actions_text, 'name="'))) AS actions
FROM layer_styles ls;
The outcome is that it doesn't like minus numbers when using strpos. I can get it go forward 6 characters to remove the 'name="' from the returned substring but cannot remove the '"/>'.
It returns the following:
View SHED Database"/>
where I want it return:
View SHED Database
Any suggestions would be greatly appreciated.
ADDITION:I have found out that if I was using 9.1 I could have used strposrev and i think the following code would have worked:
CREATE OR REPLACE VIEW vw_actions AS
SELECT ls.f_table_schema, ls.f_table_name,
(SELECT substr(ls.attribute_actions_text::text,
strpos(ls.attribute_actions_text::text, 'name="'::text)+6,
strposrev(ls.attribute_actions_text::text, '"/>'::text)+3 -
strpos(ls.attribute_actions_text::text, 'name="'::text))) AS actions
FROM layer_styles ls;
replace(ls.f_table_schema,'"/>','')
?\d tbl
in psql) and some sample values for this question.