Help with array constraints - Mailing list pgsql-general

From Jason Hihn
Subject Help with array constraints
Date
Msg-id NGBBLHANMLKMHPDGJGAPKEGGCGAA.jhihn@paytimepayroll.com
Whole thread Raw
Responses Re: Help with array constraints
Re: Help with array constraints
Re: Help with array constraints
List pgsql-general
Two tables (simplified):

CREATE TABLE _test (
    id CHAR(1),
    PRIMARY KEY(id)
);

INSERT INTO _test VALUES ('a');
INSERT INTO _test VALUES ('b');

CREATE TABLE test (
    letter CHAR(1)[3] NOT NULL REFERENCES _test(id)
    PRIMARY KEY(letter)
);

CREATE TABLE / PRIMARY KEY will create implicit index 'test_pkey' for table
'test'
NOTICE:  CREATE TABLE will create implicit trigger(s) for FOREIGN KEY
check(s)
ERROR:  Unable to identify an operator '=' for types 'character[]' and
'character'
        You will have to retype this query using an explicit cast

Can someone please explain that in English? I want ALL the letter field
values to be checked against what is in the _test table id field when a row
is inserted. For example, 'a' and 'b' is in the _test table now, if I insert
an 'a' or 'b' into test, it will suceed. If I insert a 'c' or 'd' it should
fail.

What must I do?

I am on v7.2.

Thank you.


pgsql-general by date:

Previous
From: Lonni J Friedman
Date:
Subject: Re: unable to dump database, toast errors
Next
From: Tom Lane
Date:
Subject: Re: unable to dump database, toast errors