Thread: I: TODO: Allow substring/replace() to get/set bit values
Re-reading the docs it looks like the only thing missing is get/set_bit for bit string. Substring is already implemented for bit string, and I don't really know if replace is useful at all. (sorry if the other mail came with a different sender name) Leonardo > I would like to work on "Allow substring/replace() to get/set bit values", since > it looks like a simple task. > > The item is not marked as "easy" on the TODO though. Before proceding to a > discussion on how this functions should be implemented (I got from the messages > on the mailing list that bit substring/replace functions should do it) I would > like to know if it's a complicated task.
On Mon, Jan 4, 2010 at 5:17 AM, Leonardo F <m_lists@yahoo.it> wrote: > Re-reading the docs it looks like the only thing missing is get/set_bit for bit string. > > Substring is already implemented for bit string, and I don't really know if replace is useful at all. > > (sorry if the other mail came with a different sender name) You might want to search the archives (or the wiki history, or the CVS history if it's been there since before we moved the TODO list to the wiki) for discussion of why that item was added to the TODO in the first place. ...Robert
> You might want to search the archives (or the wiki history, or the CVS > history if it's been there since before we moved the TODO list to the > wiki) for discussion of why that item was added to the TODO in the > first place. I read the thread: http://archives.postgresql.org/pgsql-hackers/2004-02/msg00478.php 1) it is true that "getbit sounds a lot like what substring() does", but the same could be said for binary string substring/get_byte;so IMHO get/set_bit should be present for bit string 2) it is not very clear to me how "setbit could actually be handled by replace()" (maybe "overlay" style?) 3) since I'm looking at byte string get/set_bit to understand how that works, I'm having a hard time understanding why thebit indexes in get/set_bit are low-first based: select get_bit(E'\\376\\376'::bytea, s) as b,s from generate_series(0,15,1) as s b s 0 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 0 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 I understand this is the internal representation, but still: if someone asked me what the 8th bit in 1111111011111110 is,I would have said 1, not 0 (assuming the first bit has index '0'). Actually, David Helgason's patch (http://archives.postgresql.org/pgsql-hackers/2004-01/msg00498.php)goes in this direction: note the bitNo = 7 - (n % 8); part. Using that algorithm would mean get/set_bit in bit string would behave differently from what they do in binary string(IMHO it's the binary string implementation that is "wrong"). Leonardo
On Tue, Jan 5, 2010 at 3:58 AM, Leonardo F <m_lists@yahoo.it> wrote: >> You might want to search the archives (or the wiki history, or the CVS >> history if it's been there since before we moved the TODO list to the >> wiki) for discussion of why that item was added to the TODO in the >> first place. > > I read the thread: > > http://archives.postgresql.org/pgsql-hackers/2004-02/msg00478.php > > 1) it is true that "getbit sounds a lot like what substring() does", but the same could be said for binary string substring/get_byte;so IMHO get/set_bit should be present for bit string > 2) it is not very clear to me how "setbit could actually be handled by replace()" (maybe "overlay" style?) > 3) since I'm looking at byte string get/set_bit to understand how that works, I'm having a hard time understanding whythe bit indexes in get/set_bit are low-first based: > > select get_bit(E'\\376\\376'::bytea, s) as b,s from generate_series(0,15,1) as s > b s > 0 0 > 1 1 > 1 2 > 1 3 > 1 4 > 1 5 > 1 6 > 1 7 > 0 8 > 1 9 > 1 10 > 1 11 > 1 12 > 1 13 > 1 14 > 1 15 > > > I understand this is the internal representation, but still: if someone asked me what the 8th bit in 1111111011111110 is,I would have said 1, not 0 (assuming the first bit has index '0'). Actually, David Helgason's patch (http://archives.postgresql.org/pgsql-hackers/2004-01/msg00498.php)goes in this direction: note the > > bitNo = 7 - (n % 8); > > part. Using that algorithm would mean get/set_bit in bit string would behave differently from what they do in binary string(IMHO it's the binary string implementation that is "wrong"). Well, I'm not really clear on what you're trying to accomplish here. As you say, there's really no point in changing the internal representation, and if you don't find replace() useful either, then why are you even working on this at all? Since the latest discussion of this is more than five years old, it's unclear that anyone even cares any more. It seems to me that making replace overlay a substring of bits could be a reasonable thing to do, but if nobody actually wants it, then the simplest thing to do is remove this from the TODO and call it good. ...Robert
> As you say, there's really no point in changing the internal > representation, and if you don't find replace() useful either, then > why are you even working on this at all? I would like a get_bit / set_bit for bit strings, as I find them useful. get_bit could be a simple call to substring, but there's no way of doing a set_bit on a bit string as far as I know. I don't like the "replace" syntax for bit strings since it won't give you the same functionality of set_bit, plus I don't really see how someone would want to look for a bit string and replace it with another bit string. But I see that someone might want to overlay a bit string with another (this is different from "replace" since you have to tell the position where the replacing would start, instead of looking for a bit string). To sum up: 1) a new function, "get_bit", that calls substring 2) a new function, "overlay", that replaces bits (starting at a certain position) 3) a new function, "set_bit", that calls overlay > Since the latest discussion > of this is more than five years old, it's unclear that anyone even > cares any more. It seems to me that making replace overlay a > substring of bits could be a reasonable thing to do, but if nobody > actually wants it, then the simplest thing to do is remove this from > the TODO and call it good. I understand: it would be both a useful feature to me and a way to start coding postgres. But, of course, if there's no interest, I'll pass...
On Tue, Jan 5, 2010 at 10:45 AM, Leonardo F <m_lists@yahoo.it> wrote: >> As you say, there's really no point in changing the internal >> representation, and if you don't find replace() useful either, then >> why are you even working on this at all? > > I would like a get_bit / set_bit for bit strings, as I find them useful. > get_bit could be a simple call to substring, but there's no way of doing a set_bit on a bit string as far as I know. > > I don't like the "replace" syntax for bit strings since it won't give you the same functionality of set_bit, > plus I don't really see how someone would want to look for a bit string and replace it with another bit string. > But I see that someone might want to overlay a bit string with another (this is different from "replace" since you > have to tell the position where the replacing would start, instead of looking for a bit string). > > To sum up: > > 1) a new function, "get_bit", that calls substring > 2) a new function, "overlay", that replaces bits (starting at a certain position) > 3) a new function, "set_bit", that calls overlay That seems reasonable to me. Not sure what others think. >> Since the latest discussion >> of this is more than five years old, it's unclear that anyone even >> cares any more. It seems to me that making replace overlay a >> substring of bits could be a reasonable thing to do, but if nobody >> actually wants it, then the simplest thing to do is remove this from >> the TODO and call it good. > > I understand: it would be both a useful feature to me and a way to start coding postgres. > > But, of course, if there's no interest, I'll pass... I wouldn't jump to that conclusion. I just wasn't sure what you were trying to do, but it's more clear now. ...Robert
> > To sum up: > > > > 1) a new function, "get_bit", that calls substring > > 2) a new function, "overlay", that replaces bits (starting at a certain > position) > > 3) a new function, "set_bit", that calls overlay > > That seems reasonable to me. Not sure what others think. Is anybody interested? Otherwise the entry could be removed from the TODO list... Leonardo
On Wed, Jan 6, 2010 at 1:21 PM, Leonardo F <m_lists@yahoo.it> wrote: >> > To sum up: >> > >> > 1) a new function, "get_bit", that calls substring >> > 2) a new function, "overlay", that replaces bits (starting at a certain >> position) >> > 3) a new function, "set_bit", that calls overlay >> >> That seems reasonable to me. Not sure what others think. > > Is anybody interested? Otherwise the entry could be removed from the TODO list... Even if not, you can still submit a patch. There are a lot more users of PG than there are people who read -hackers. ...Robert
> > Is anybody interested? Otherwise the entry could be removed from the TODO > list... > > Even if not, you can still submit a patch. There are a lot more users > of PG than there are people who read -hackers. Ok, I'll try and submit a patch. Thank you very much.