Re: Function to return number of words in a string? - Mailing list pgsql-general

From Peter Fein
Subject Re: Function to return number of words in a string?
Date
Msg-id 20050509131542.6713399e@layout.pfein.org
Whole thread Raw
In response to Function to return number of words in a string?  (Peter Fein <pfein@pobox.com>)
List pgsql-general
On 05/09/05 11:21 AM CDT, Peter Fein <pfein@pobox.com> said:
> Hiya-
>
> I'm looking for a function to return the number of words in a string,
> split on whitespace.  I'm coming from python, so I may just write it
> in that but I wanted to check first.  In python, one would write:
>
> s="some string or other"
> len(s.split())

For the archives:

CREATE OR REPLACE FUNCTION word_length(text)
  RETURNS int4 AS
'return len(args[0].split())'
  LANGUAGE 'plpythonu' IMMUTABLE STRICT;

Thanks all.

--
Peter Fein                 pfein@pobox.com                 773-575-0694

Basically, if you're not a utopianist, you're a schmuck. -J. Feldman

pgsql-general by date:

Previous
From: Brendan Jurd
Date:
Subject: Re: Shorthand for foreign key indices
Next
From: "Craig Bryden"
Date:
Subject: Clustering Database Servers