Search code examples
postgresqlpostgresql-9.2string-function

How to find the character in nth position in a string


For example,

create table tblvarchar 
(
lngvarchar character varying(500)
)

And Sample Row is

insert into tblvarchar (lngvarchar) values ('110010000001111101010011110000001101011000001')
  • How to find out the character(this case (0 or 1)) in lngvarchar field using the position of character ?
  • for example, the character in 15th position of lngvarchar is 1

On PostgreSQL 9.2.4


Solution

  • You can do this (start position 15, length 1 example):

    SELECT SUBSTRING(lngvarchar,15,1) FROM tblvarchar;
    

    SQL FIDDLE