0

In Spring+Hibernate app im trying to use a named parameter pasend query should sum values from xml document saved in database as text.

    SELECT  document_type, 
     SUM(CAST(substring(document_content ,'<ab.*>(.*[0-9])</ab>') as float)) as value, COUNT(*)
     FROM  statistic_data_test 
     WHERE column LIKE :param1::text
     GROUP BY document_type 
     ORDER BY value DESC 

param1 is named parameter passed to program via URL. Whole query and parameter names are dynamically created by user.

code shown above works fine, but i need an ability to find not only exact match, but i cant concatenate stings in query. For now, in one part of code i'm checking if type is text, and if so, i add % marks as suffix and prefix.

What i wont, is move % marks from parameter to query string, but things like

WHERE column LIKE '%'+:param1::text+'%'

turns errors

How can it be done? How to concatenate stings in query?

1 Answer 1

1

Change the strategy, keep the goal.

Use the position function.

position(:param1::text in column) <> o
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it looks what i was looking for ;) But is there a way to check if nothing else except that param is in column? Cant be done by LIKE ofc, but would be good to use one method.
@T.G - Well, LIKE can do that simply by including no percent signs, but you would suffer a major performance hit on any larger data if you did not just use = for that job. Hammer for the nails, screwdriver for the screws.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.