Lists: | pgsql-general |
---|
From: | Heine Ferreira <heine(dot)ferreira(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | citext question |
Date: | 2012-10-13 21:48:53 |
Message-ID: | CAMuqQjdny2hkWpmQxwDjaHHnEgWbQQABmyUzgp4JZZ_pYTyDFg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hi
I have played around a bit with the citext
extention. It looks like it is a lot like the
text data type - allmost like a memo
field. Is there any way to restrict the
length of citext fields, like char and
varchar fields?
Thanks
H.F.
From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | Heine Ferreira <heine(dot)ferreira(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: citext question |
Date: | 2012-10-13 22:34:45 |
Message-ID: | 4B444FA2-AF2B-4D8E-9C07-E3E279145F80@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Oct 13, 2012, at 17:48, Heine Ferreira <heine(dot)ferreira(at)gmail(dot)com> wrote:
> Hi
>
> I have played around a bit with the citext
> extention. It looks like it is a lot like the
> text data type - allmost like a memo
> field. Is there any way to restrict the
> length of citext fields, like char and
> varchar fields?
>
> Thanks
>
> H.F.
>
Try "citext(25)"...if it works then "yes" otherwise "no"...
David J.
From: | Vibhor Kumar <vibhor(dot)kumar(at)enterprisedb(dot)com> |
---|---|
To: | David Johnston <polobo(at)yahoo(dot)com> |
Cc: | Heine Ferreira <heine(dot)ferreira(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: citext question |
Date: | 2012-10-13 23:31:37 |
Message-ID: | 31563762-B77A-4636-9A36-5091E21F7286@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Oct 13, 2012, at 6:34 PM, David Johnston <polobo(at)yahoo(dot)com> wrote:
>>
>> Hi
>>
>> I have played around a bit with the citext
>> extention. It looks like it is a lot like the
>> text data type - allmost like a memo
>> field. Is there any way to restrict the
>> length of citext fields, like char and
>> varchar fields?
>>
>> Thanks
>>
>> H.F.
>>
>
> Try "citext(25)"...if it works then "yes" otherwise "no"...
No, citext(length) not supported.
However, you can define check constraint, if that fulfill your requirement as given below:
create table test2(col citext check(length(col) < 3));
Or
you can create a domain which you can use in CREATE TABLE command as given below:
CREATE domain citext_char as CITEXT CHECK(length(value) <= 3);
Thanks & Regards,
Vibhor Kumar
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Blog: http://vibhork.blogspot.com
From: | Craig Ringer <ringerc(at)ringerc(dot)id(dot)au> |
---|---|
To: | Heine Ferreira <heine(dot)ferreira(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: citext question |
Date: | 2012-10-14 03:48:01 |
Message-ID: | 507A35F1.8060809@ringerc.id.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On 10/14/2012 05:48 AM, Heine Ferreira wrote:
> Hi
>
> I have played around a bit with the citext
> extention. It looks like it is a lot like the
> text data type - allmost like a memo
> field. Is there any way to restrict the
> length of citext fields, like char and
> varchar fields?
First, don't use "char(n)" or plain "char". Neither do what you (as a
sane and sensible person) probably expect them to do.
In PostgreSQL, "varchar(n)" is effectively the same as "text" with a
"length(col_name) <= n" CHECK constraint. There is no difference in how
they are stored, and there's no advantage to using "varchar" over "text".
It's similar with citext. While citext doesn't accept a typmod to
constrain its length, you can and should use CHECK constraints as
appropriate in your data definitions.
--
Craig Ringer