Re: String manipulation
От | pativo@arcor.de (pativo) |
---|---|
Тема | Re: String manipulation |
Дата | |
Msg-id | 58babf1b.0402180117.31e1cc91@posting.google.com обсуждение исходный текст |
Ответ на | String manipulation (pativo@arcor.de (pativo)) |
Список | pgsql-general |
pativo@arcor.de (pativo) wrote in message news:<58babf1b.0402170346.4a719868@posting.google.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 -- www.pativo.de
В списке pgsql-general по дате отправления: