Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCTFf-0001nJ-3v for pgsql-general@arkaria.postgresql.org; Tue, 25 Jan 2022 21:21:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCTFd-0000vM-26 for pgsql-general@arkaria.postgresql.org; Tue, 25 Jan 2022 21:21:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCTFc-0000vC-M7 for pgsql-general@lists.postgresql.org; Tue, 25 Jan 2022 21:21:16 +0000 Received: from smtp-outgoing-1701.laposte.net ([160.92.124.99]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCTFX-0005Gw-9w for pgsql-general@lists.postgresql.org; Tue, 25 Jan 2022 21:21:15 +0000 X-mail-filterd: {"version":"1.3.4","queueID":"4Jk0C51dFFzPjd8","contextId":"3a6db3ac-0f3b-4df8-8188-67198cdff4cf"} Received: from outgoing-mail.laposte.net (localhost.localdomain [127.0.0.1]) by mlpnf0117.laposte.net (SMTP Server) with ESMTP id 4Jk0C51dFFzPjd8; Tue, 25 Jan 2022 22:21:05 +0100 (CET) X-mail-filterd: {"version":"1.3.4","queueID":"4Jk0C516XKzPjct","contextId":"c3ff7388-f1fb-412d-b5b3-d5ebbcb95ca4"} X-lpn-mailing: LEGIT X-lpn-spamrating: 46 X-lpn-spamlevel: not-spam X-lpn-spamcause: OK, (-100)(0000)gggruggvucftvghtrhhoucdtuddrgedvvddrvdelgddugeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecunfetrffquffvgfdpggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffgggjggtsehgtderofdtfeejnecuhfhrohhmpegsvghnjhdruggvvheslhgrphhoshhtvgdrnhgvthenucggtffrrghtthgvrhhnpeeitdfhjedvgfffveejfeejtdejvdegheekgeejkeeuheeujeeileethfeuheeuteenucfkphepjeekrdduleekrddvgedvrdduvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepjeekrdduleekrddvgedvrdduvdejpdhhvghloheplgduledvrdduieekrddtrddutdgnpdhmrghilhhfrhhomhepsggvnhhjrdguvghvsehlrghpohhsthgvrdhnvghtpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepshhhihhshhgrohiihhhonhhgsehgmhgrihhlrdgtohhmpdhmohguvgepshhmthhpohhuth Received: from [192.168.0.10] (unknown [78.198.242.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mlpnf0117.laposte.net (SMTP Server) with ESMTPSA id 4Jk0C516XKzPjct; Tue, 25 Jan 2022 22:21:05 +0100 (CET) Subject: Re: Counting the number of repeated phrases in a column To: Shaozhong SHI , pgsql-general References: From: benj.dev@laposte.net Message-ID: Date: Tue, 25 Jan 2022 22:21:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7t33CpKxKpxTSTT5MjtZFDDaHnOXM6wFH" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=laposte.net; s=lpn-wlmd; t=1643145668; bh=VPH6s0KRQ/xOzyNVdgOLIfAC9JqfoeLJ39ssLJ2lPAg=; h=Subject:To:References:From:Message-ID:Date:MIME-Version:In-Reply-To:Content-Type; b=pI5Xtgn7HnUBObw1aXIcjuJg8c7GGOBjtTSsteRjffBOPtcmg/K7vcxPO2uvNeCPMpHxcs/EOU0zzJksyBMmfENrMpxx28Iap3npCuSsUQYocycGWVHJMns6NJo5b7Tq+bBxo+ioX1dmBGqeBjQtEVVjYOCOyVHLnKue90ijxdbmqnOfI/3VvEfllhnfW8PjlzfTiNglgHXZxgaQlOXbWnJ3NIbN052POCs9oGHX+HPxFaZ0tJ3qt2AZnpp8X3IlUab7i1wHadmQ5WAcCHmB1LjzxOolgKWNROnWijq9IymKXhOcwBhrOmtdLNt+zJl5HQdSU0chPGbG28cCjz88/g==; List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7t33CpKxKpxTSTT5MjtZFDDaHnOXM6wFH Content-Type: multipart/mixed; boundary="swsdNgRqDnOROHHVmcQkVyIfrHBYKxp9o"; protected-headers="v1" From: benj.dev@laposte.net To: Shaozhong SHI , pgsql-general Message-ID: Subject: Re: Counting the number of repeated phrases in a column References: In-Reply-To: --swsdNgRqDnOROHHVmcQkVyIfrHBYKxp9o Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: quoted-printable Le 25/01/2022 =C3=A0 18:10, Shaozhong SHI a =C3=A9crit=C2=A0: > There is a short of a function in the standard Postgres to do the follo= wing: >=20 > It is easy to count the number of occurrence of words, but it is rather= =20 > difficult to count the number of occurrence of phrases. >=20 > For instance: >=20 > A cell of value:=C2=A0 'Hello World' means 1 occurrence a phrase. >=20 > A cell of value: 'Hello World World Hello' means no occurrence of any=20 > repeated phrase. >=20 > But, A cell of value: 'Hello World World Hello Hello World' means 2=20 > occurrences of 'Hello World'. >=20 > 'The City of London, London' also has no occurrences of any repeated ph= rase. >=20 > Anyone has got such a function to check out the number of occurrence of= =20 > any repeated phrases? >=20 > Regards, >=20 > David Don't know if it's exactly what you want, but you can replace all=20 occurence of the phrase in the text by empty string and compute the diff = between the initial and the result and next divide by the length of your = phrase. Example : WITH x AS (SELECT 'toto like tata and toto like titi and toto like tutu' = , 'toto like' phrase) SELECT (char_length(texte) - char_length(replace(texte, phrase, ''))) /=20 char_length(phrase) AS nb_occurence FROM x --swsdNgRqDnOROHHVmcQkVyIfrHBYKxp9o-- --7t33CpKxKpxTSTT5MjtZFDDaHnOXM6wFH Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQSkS3tpag0IFuyrNn7u5vY6QwMtDgUCYfBpwQUDAAAAAAAKCRDu5vY6QwMtDvMF AJ99yKDlOjxzKOtjYEZVDJyhooX4BwCfW99D3BxFO1vcslFld0wG76XSBmw= =/pJJ -----END PGP SIGNATURE----- --7t33CpKxKpxTSTT5MjtZFDDaHnOXM6wFH--