In SQL Server (T-SQL) we can do this like posted here:
http://www.sqlrelease.com/allow-only-alphanumeric-characters-in-a-column
How to do the same in PostgreSQL?
The following didn't worked -
CREATE OR REPLACE FUNCTION dummy.checkalphanumeric(username character varying(32))
RETURNS integer AS
$BODY$
BEGIN
RETURN (SELECT CASE WHEN regexp_matches(username, '%[^a-zA-Z0-9]%') >
false THEN false ELSE true END);
END; $BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION dummy.checkalphanumeric(username character varying(32))
OWNER TO postgres;
And the ALTER query -
ALTER TABLE dummy.provisioning_user ADD CONSTRAINT
CK_provisioning_user CHECK (dummycheckalphanumeric(username) = 1)