how to extract and use a string like a constraint? - Mailing list pgsql-novice

From Jean-Yves F. Barbier
Subject how to extract and use a string like a constraint?
Date
Msg-id 20100707221316.1fc01f98@anubis.defcon1
Whole thread Raw
Responses Re: how to extract and use a string like a constraint?
List pgsql-novice
Hi listers,

I've got a table that describes a field and its constraint, but I don't
have any clue about how to extract and use this constraint as if it was on
a regular field line:

CREATE TABLE tstfld (
   id        serial       primary key,
   fieldtype VARCHAR(128) NOT NULL CHECK(char_length(fieldtype) > 2),
   length    SMALLINT     DEFAULT NULL,
   chk       TEXT         DEFAULT NULL
) WITHOUT OID;

INSERT INTO tstfld VALUES (
   default,
   'CHAR',
   2,
   E'CHECK((char_length(fieldtype) = 2) AND (fieldtype ~ ^\\d{2}::text))'
);


and I also don't understand why this don't work:
SELECT char_length(SELECT chk FROM tstchk WHERE id=1);
Can it only be use with a temp var into a proc?


--
Outside of a dog, a book is a man's best friend.  Inside a dog it's too
dark to read. - Groucho Marx

pgsql-novice by date:

Previous
From: "John T. Dow"
Date:
Subject: Re: Dropped table, no backup, restore from file system backup or WAL files?
Next
From: Tim Landscheidt
Date:
Subject: Re: how to extract and use a string like a constraint?