For example,
create table tblvarchar
(
lngvarchar character varying(500)
)
And Sample Row is
insert into tblvarchar (lngvarchar) values ('110010000001111101010011110000001101011000001')
character
(this case (0
or 1
)) in lngvarchar
field using the position of character
?character
in 15th position of lngvarchar
is 1
On PostgreSQL 9.2.4
You can do this (start position 15, length 1 example):
SELECT SUBSTRING(lngvarchar,15,1) FROM tblvarchar;
SQL FIDDLE
If your data contains only 0
and 1
, you might want to use bit strings instead of character varying
(bit varying
in your case).
You can use the get_bit()
function to get a single bit (but that function use zero based indexing); also substring()
works on bit strings too (but will give you text
results).
SQLFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With