Re: constraining chars for all cols of a table

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: constraining chars for all cols of a table
Дата
Msg-id 057e01cbcfb4$aabe4410$003acc30$@yahoo.com
обсуждение исходный текст
Ответ на constraining chars for all cols of a table  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Ответы Re: constraining chars for all cols of a table  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Список pgsql-general

Restrict access to the table (for inserts) to a function that does the verification and then executes the insert in addition to any kind of logging and “RAISE”ing you need.

 

If you need to validate existing data I’d probably just do some one-time verifications and updates where required. 

 

A column “CHECK” constraint, however, seems like it should work just find if you use a regular expression – and I cannot imagine it would be that performance limiting.

 

Without a more specific model in mind choosing between different approaches is difficult.

 

David J.

 

 

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Gauthier, Dave
Sent: Friday, February 18, 2011 4:24 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] constraining chars for all cols of a table

 

Hi:

 

I have to constrain the chars used for table columns.  For example...

   create table foo (col1 text, col2 text, col3 text);

... where

    col1 has to be all uppercase, nothing but [A-Z]

    col2 has to be all lowercase [a-z] plus [0-9] is also allowed

    col3 can be mixed case plus [0-9] and sqr brackets (but nothing else).

 

I could put a check constraint on each/every table column, but that seems complicated and potentially slow.

 

I could do this check using the existing insert and update before triggers, but then I'd have to loop through all the columns and decide one by one how to

check them.  Again, slow and complicated.

 

Is there a better way?  Whatever I do, I'd have to be able to capture violations to provide informative feedback  to the users through the perl script that'll actually be doing the insert/update.

 

Thanks in Advance !

 

В списке pgsql-general по дате отправления:

Предыдущее
От: Vick Khera
Дата:
Сообщение: Re: Canceling a DELETE query
Следующее
От: "Gauthier, Dave"
Дата:
Сообщение: Re: constraining chars for all cols of a table