Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D7419633A8B for ; Tue, 2 Feb 2010 16:48:40 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 88342-01-7 for ; Tue, 2 Feb 2010 20:48:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f222.google.com (mail-ew0-f222.google.com [209.85.219.222]) by mail.postgresql.org (Postfix) with ESMTP id A13EE637A65 for ; Tue, 2 Feb 2010 16:38:44 -0400 (AST) Received: by ewy22 with SMTP id 22so176651ewy.34 for ; Tue, 02 Feb 2010 12:38:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=+7yAkM7s1hW3xCrpfViV3MIpJohVuNebCx6Ld0t8mT4=; b=V9lAS4lZOowYGdBg1KfoBifEFZ7iyvLfC/icRYc+zI0f6e1/u+rdlY3rNVbR1jrf+D 5dtZD4W79rpcMG9DAWM9QRH/z1oy79kRB7Qhucqss1fzo6v6ZNgiLDyKNkMEV+/DnVVv eUuOpKmXWAr8uzOTBYl/2CfOZp7+fTnCe1/RM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=cgyV85ZV786NzUQIFWAQCxay4F3NgmorAbHQyDPK/Ncj3CO33FNT0JmXJHVvSPbkmu kgSxFQ0io9hlFdjOCiqOnYpJTE6alUfr5n+eoH/F9lATRKi28FQFA/yr1oQ9ctD9kxRS rTUPibPXOxFEV87v6SvjdNVophQ8uEzv2sq7U= MIME-Version: 1.0 Received: by 10.216.88.65 with SMTP id z43mr53271wee.5.1265143123046; Tue, 02 Feb 2010 12:38:43 -0800 (PST) In-Reply-To: References: Date: Tue, 2 Feb 2010 21:38:42 +0100 Message-ID: <162867791002021238j31ad8d7cge44bbce28ff451f3@mail.gmail.com> Subject: Re: please help me on regular expression From: Pavel Stehule To: Tena Sakai Cc: "pgsql-sql@postgresql.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.528 tagged_above=-10 required=5 tests=AWL=0.071, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/23 X-Sequence-Number: 33622 2010/2/2 Tena Sakai : > Hi everybody, > > I need a bit of help on postgres reqular expression. > With a table of the following definition: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Table "tsakai.pheno" > =C2=A0Column =C2=A0 | =C2=A0 =C2=A0 =C2=A0 Type =C2=A0 =C2=A0 =C2=A0 =C2= =A0| Modifiers > -----------+-------------------+----------- > =C2=A0subjectid | integer =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | not null > =C2=A0height =C2=A0 =C2=A0| character varying | not null > =C2=A0race =C2=A0 =C2=A0 =C2=A0| character varying | not null > =C2=A0blood =C2=A0 =C2=A0 | character varying | not null > > I want to catch entries in height column that includes a > decimal point. =C2=A0Here's my attempt: > > =C2=A0select subjectid, height > =C2=A0 from tsakai.pheno > =C2=A0where height ~ '[:digit:]+.[:digit:]+'; > > Which returns 0 rows, but if I get rid of where clause, > I get rows like: > > =C2=A0subjectid | height > -----------+-------- > =C2=A0 =C2=A0 55379 | 70.5 > =C2=A0 =C2=A0 55383 | 69 > =C2=A0 =C2=A0 55395 | 70 > =C2=A0 =C2=A0 56173 | 71 > =C2=A0 =C2=A0 56177 | 65.5 > =C2=A0 =C2=A0 56178 | 70 > =C2=A0 =C2=A0 =C2=A0 . =C2=A0 =C2=A0 =C2=A0. > =C2=A0 =C2=A0 =C2=A0 . =C2=A0 =C2=A0 =C2=A0. > > And when I escape that dot after first plus sign with a backslash, > like this: > =C2=A0where height ~ '[:digit:]+\.[:digit:]+'; > then I get complaint: > > WARNING: =C2=A0nonstandard use of escape in a string literal > LINE 3: where height ~ '[:digit:]+\.[:digit:]+'; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 ^ > HINT: =C2=A0Use the escape string syntax for escapes, e.g., E'\r\n'. > > From there, it was a downward spiral descent... > you have to use a prefix 'E' - E'some string with \backslash' for your case the reg. expr could be postgres=3D# select '70.5' ~ e'\\d+\.\\d+'; ?column? ---------- t (1 row) http://www.postgresql.org/docs/8.1/static/functions-matching.html or postgres=3D# select '70.5' ~ e'[[:digit:]]+\.[[:digit:]]+'; ?column? ---------- t (1 row) Regards Pavel Stehule > Please help. > > Thank you. > > Regards, > > Tena Sakai > tsakai@gallo.ucsf.edu > > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql >