| From: | Raymond O'Donnell <rod(at)iol(dot)ie> |
|---|---|
| To: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Constraint: string length must be 32 chars |
| Date: | 2010-10-16 16:27:14 |
| Message-ID: | 4CB9D262.6000309@iol.ie |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On 16/10/2010 17:15, Alexander Farber wrote:
> Hello,
>
> I'm trying to create a table, where md5 strings will serve as primary keys.
> So I'd like to add a constraing that the key length should be 32 chars long
> (and contain [a-fA-F0-9] only):
>
> create table gps (
> id varchar(32) primary key CONSTRAINT char_length(id)==32,
> stamp timestamp DEFAULT current_timestamp,
> pos point);
>
> But it fails:
>
> ERROR: syntax error at or near "("
> LINE 2: id varchar(32) primary key CONSTRAINT char_length(id)==32,
> ^
> Does anybody please know what's wrong here?
From (somewhat hazy) memory, I think the syntax is something like this:
... CONSTRAINT length_check CHECK char_length(id) = 32, ...
Note also that the equality operator is a single "=", not "==" as you
have above.
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexander Farber | 2010-10-16 16:48:51 | Re: Constraint: string length must be 32 chars |
| Previous Message | Rob Sargent | 2010-10-16 16:25:15 | Re: installing from source in Windows |