Re: Operation on bit strings with different length - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: Operation on bit strings with different length
Date
Msg-id Pine.LNX.4.30.0112181721220.637-100000@peter.localdomain
Whole thread Raw
In response to Operation on bit strings with different length  (S P Arif Sahari Wibowo <arifsaha@yahoo.com>)
List 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@gmx.net



pgsql-sql by date:

Previous
From: Iklódi Lajos
Date:
Subject: Re: Execution time problem
Next
From: Gurudutt
Date:
Subject: Maximum Execution Timeout Error!!