From: | pativo(at)arcor(dot)de (pativo) |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: String manipulation |
Date: | 2004-02-18 09:17:01 |
Message-ID: | 58babf1b.0402180117.31e1cc91@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
pativo(at)arcor(dot)de (pativo) wrote in message news:<58babf1b(dot)0402170346(dot)4a719868(at)posting(dot)google(dot)com>...
Hello and thanks to all!
I'm amused that I get so many responses.
Ok, at time I use a plpgsql function (isAHex(VARCHAR)) which checks only
if the length is even.
So I think I should implement the following.
=======8<-------------------------------------------------------------------
CREATE FUNCTION isAHex(VARCHAR) RETURNS BOOLEAN AS '
DECLARE
input_text_p ALIAS FOR $1;
tmp_char VARCHAR;
BEGIN
IF ((length(input_text_p) % 2) <> 0) THEN
RETURN FALSE;
END IF;
FOR i IN 1..length(input_text_p) LOOP
tmp_char := substr(input_text_p, i, 1);
IF NOT tmp_char ~ ''[0-9a-fA-F]'' THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END;
' LANGUAGE 'plpgsql';
CREATE TABLE textsTest (
surrogate VARCHAR(40) PRIMARY KEY,
hex_text VARCHAR(150) NOT NULL CHECK(isAHexTest(hex_text))
);
=======8<-------------------------------------------------------------------
But for next release I will use the following. This is in my eyes
the better solution.
=======8<-------------------------------------------------------------------
CREATE TABLE textsTest (
surrogate VARCHAR(40) PRIMARY KEY,
hex_text TEXT NOT NULL CHECK(text ~ '^([0-9A-Fa-f]{2})+$')
);
=======8<-------------------------------------------------------------------
Thanks to all!!!
oki,
pativo
From | Date | Subject | |
---|---|---|---|
Next Message | Shridhar Daithankar | 2004-02-18 09:37:14 | Re: Grant / Revoke functionality |
Previous Message | Alexander Priem | 2004-02-18 09:11:00 | Re: Grant / Revoke functionality |