Way to try multiple SELECTs till a result is available?

前端 未结 4 748
梦毁少年i
梦毁少年i 2020-11-27 23:36

What if I want to search for a single row in a table with a decrementing precision, e.g. like this:

SELECT * FROM image WHERE name LIKE \'text\' AND group_id         


        
4条回答
  •  囚心锁ツ
    2020-11-28 00:19

    It's late and I don't feel like writing out a full solution, but if I needed this I would probably create a customer function that returned a customer type, record or a table (depending on what your needs are). The advantage to this would be that once you found your record, you could stop.

    Making the number of params be dynamic will make it a bit more challenging. Depending on your version of PostgreSQL (and the extension available to you), you might be able to pass in an hstore or json and dynamically build the query.

    Maybe not the greatest SO answer, but it's more than a comment and hopefully some food for thought.

提交回复
热议问题