简体   繁体   中英

Best way to store ranges and single values in mysql

just facing a little problem right now.

I have a layout-table that contains one field pages . This should specify for which pages the layout should be applied.

The possible contents are "closed" ranges like '3-5' or open ranges like '3-*' . But it should also be possible to add single pages.

So is there a good way to accomplish a content like that

'3-5;11;15;17-*'

in a single field?

Or do you know better ways?

Is there a possibility to query this field like

SELECT * WHERE IN_RANGE(pages, '5') (Pseudo-Code)

I want to prevent creating a table page because it would contain nothing else and also don't want to do the validation in php.

I am happy to provide more information if necessary.

This is a tricky question i dont see "native" sql option for this. My first idea was to store information about pages as varchar and implement method to tokenize that string so youll have values which you can then process by sql query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM