String manipulation - Mailing list pgsql-general

From pativo@arcor.de (pativo)
Subject String manipulation
Date
Msg-id 58babf1b.0402170346.4a719868@posting.google.com
Whole thread Raw
Responses Re: String manipulation  (Ron St-Pierre <rstpierre@syscor.com>)
Re: String manipulation  (Bruno Wolff III <bruno@wolff.to>)
Re: String manipulation  (Pascal Polleunus <ppo@beeznest.net>)
List pgsql-general
Hello to all,

I have small problem. I have some database fields (VARCHAR)
and these field should hold some ahex coded values. So the
string length must be even and each character can only be
0-9, a-f or A-F.
My idea was that:

====8<-----------------------------------

CREATE TABLE test (
    id   INT4         PRIMARY KEY NOT NULL DEFAULT nextID(),
    text VARCHAR(150) NOT NULL CHECK(isAHex(text))
);

CREATE FUNCTION isAHex(VARCHAR) RETURNS BOOLEAN AS '
   DECLARE
      text_p ALIAS FOR $1;
   BEGIN
      IF ((length(text_p) % 2) <> 0) THEN
         RETURN FALSE;
      END IF;
      -- TODO How to check each character
      RETURN TRUE;
   END;
' LANGUAGE 'plpgsql';

====8<-----------------------------------

Has anybody an idea how could I check each character?
I would prefer a solution in plpgsql!!

Thank!


pativo

--
      \\://
      (- 0)
---ooO-(_)-Ooo---

pgsql-general by date:

Previous
From: "Greg Patnude"
Date:
Subject: Re: Repost: Syntax - or unavailability of same - for variable join??? Can anyone help?
Next
From: "Ben"
Date:
Subject: Re: Repost: Syntax - or unavailability of same - for variable join??? Can anyone help?