Re: Function to return number of words in a string?

From: Peter Fein <pfein(at)pobox(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Function to return number of words in a string?
Date: 2005-05-09 18:15:42
Message-ID: 20050509131542.6713399e@layout.pfein.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 05/09/05 11:21 AM CDT, Peter Fein <pfein(at)pobox(dot)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(at)pobox(dot)com 773-575-0694

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Bryden 2005-05-09 18:41:33 Clustering Database Servers
Previous Message Brendan Jurd 2005-05-09 18:03:53 Re: Shorthand for foreign key indices