Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4AF4F1337B58 for ; Mon, 7 Mar 2011 18:08:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 50831-05 for ; Mon, 7 Mar 2011 22:08:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wy0-f174.google.com (mail-wy0-f174.google.com [74.125.82.174]) by mail.postgresql.org (Postfix) with ESMTP id DADCF1337B4E for ; Mon, 7 Mar 2011 18:08:10 -0400 (AST) Received: by wyg36 with SMTP id 36so4646195wyg.19 for ; Mon, 07 Mar 2011 14:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Zpy/aYeA+ETXo0601ahDI0YXFKcwbGkChC/hl8J9IRU=; b=QMaHxDz75iBstT4wxDC+hArjUtcMvmvwNrch/fb4iuU14G8V52d95BW/TSqNRhbZS1 4HrtuPxgMOJHLnU53i88d3NsksXZhzX9cn/rlxQBxY/m+XktLuz9guXoCxnHGJYnkdG6 Yivt5dBLi2bn7m0u/DYL0m4REWk815sm2sJ90= 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; b=lKBs5rXU95WWuTpn/3VloLc+DRCpeTBBPnlIZ8expliCLi8/VXnr0Lu/GZa/lh0kl9 ZffSlT5SvlNXcyB4L5qywbX1wFiF8ks737lIWhcTDZdTbESzNerL07kWRaShXz4gcIkc 73omshH9VhDEOgYY5mfKesTTkzCTvaSNWXDcs= MIME-Version: 1.0 Received: by 10.216.159.69 with SMTP id r47mr2741478wek.105.1299535690103; Mon, 07 Mar 2011 14:08:10 -0800 (PST) Received: by 10.216.163.145 with HTTP; Mon, 7 Mar 2011 14:08:10 -0800 (PST) In-Reply-To: <4D754C0E.4030804@techbaza.pl> References: <4D754C0E.4030804@techbaza.pl> Date: Mon, 7 Mar 2011 14:08:10 -0800 Message-ID: Subject: Re: A function to count all ocurrences of a character within a string. From: bricklen To: Piotr Czekalski Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201103/12 X-Sequence-Number: 35214 On Mon, Mar 7, 2011 at 1:20 PM, Piotr Czekalski wrote: > Hello pgsql community, > > Is there any string function (other than regex / scan & compare loop) to > obtain a list (or even a count) of characters within a string? > strpos and position seems to return only first occurence of a char/string > within substring. > The goal is to check if a string contains equal number of opening and > closing parenthesis, and if there are any of them. > > Regards, > > Piotr Czekalski Couple examples here that might help to get you started http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Get_count_of_substrings_in_string