Re: Array or not Array?

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Atif Jung <atifjung(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Array or not Array?
Date: 2010-03-03 11:01:35
Message-ID: bddc86151003030301o11a6c35erfa1a09fe4539d44b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 3 March 2010 10:48, Atif Jung <atifjung(at)gmail(dot)com> wrote:
> If I have a table as follows:
>
> CREATE TABLE test1 (a char(5));
>
> how would I test that the 2nd character of column a is NOT the letter 'b'
> for example.
>
> In Informix I would say:
>
> SELECT count(*) FROM test1 where a[2] <> 'b';
>
> In POSTGRES I get an error saying "ERROR:  cannot subscript type character
> because it is not an array". I understand why I'm getting the error,  but
> I'm not sure how I do what I want to do?
>

You can use a regular expression like:

SELECT count(*) FROM test1 where a !~ '^.b';

Regards

Thom

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message A. Kretschmer 2010-03-03 11:08:46 Re: Array or not Array?
Previous Message Atif Jung 2010-03-03 10:48:31 Array or not Array?