Re: Operation on bit strings with different length

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: S P Arif Sahari Wibowo <arifsaha(at)yahoo(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Operation on bit strings with different length
Date: 2001-12-18 22:23:52
Message-ID: Pine.LNX.4.30.0112181721220.637-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice pgsql-sql

S P Arif Sahari Wibowo writes:

> Do you know how to operate (AND, OR, etc.) on bit strings with
> dynamically different length? It is dynamic, means the length won't be
> determined until run time.
> Is there any function to extend the length of a bit string to a certain
> length?

Something along the lines of

SUBSTRING ( your_value || B'000000000000...long enough...000' FROM 1 FOR max_length )

The reason this is not done automatically is that it's not clear whether
the extension should be to the left or to the right. Either of these
could be appropriate, depending on whether you consider bit strings to be
strings or numbers. Once you know what you want in your application you
can wrap the above into a function. To generate a generic "long enough"
value, look at the REPEAT function.

--
Peter Eisentraut peter_e(at)gmx(dot)net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2001-12-18 22:30:01 Re: More on Too Many Open Files... NetBSD
Previous Message Bruce Momjian 2001-12-18 22:23:23 Re: Too Many Open Files... NetBSD

Browse pgsql-novice by date

  From Date Subject
Next Message Giorgio Ponza 2001-12-19 13:03:50 Stupid question on INDEXES
Previous Message Josh Berkus 2001-12-18 16:37:46 Re: Operation on bit strings with different length

Browse pgsql-sql by date

  From Date Subject
Next Message Gurudutt 2001-12-19 09:28:51 Maximum Execution Timeout Error!!
Previous Message Iklódi Lajos 2001-12-18 20:36:37 Re: Execution time problem