Actually, i have a need to store the numbers like "AS2303",
TS3381"(first 2 alphabets,next 3 numbers). What i want is, i have to
assign the integrity which can check the following values,
23334, ASDER, SDE23, 233A4 and like this.
If i assign as a character type domain.Then i can't check the above
cases.
Can anyone help me?
I am using postgresql(for your information).
Brian Selzer - 17 Jan 2008 12:59 GMT
> Actually, i have a need to store the numbers like "AS2303",
> TS3381"(first 2 alphabets,next 3 numbers). What i want is, i have to
[quoted text clipped - 4 lines]
> Can anyone help me?
> I am using postgresql(for your information).
Haven't you heard of a check constraint?
Bob Badour - 17 Jan 2008 13:45 GMT
> Actually, i have a need to store the numbers like "AS2303",
> TS3381"(first 2 alphabets,next 3 numbers). What i want is, i have to
[quoted text clipped - 4 lines]
> Can anyone help me?
> I am using postgresql(for your information).
If I recall correctly, postgresql has some support for regular expressions:
http://www.postgresql.org/docs/8.1/static/functions-matching.html
Does it support general constraints with a CHECK keyword? Yes it does:
http://www.postgresql.org/docs/8.1/static/ddl-constraints.html
Evan Keel - 17 Jan 2008 17:23 GMT
> Actually, i have a need to store the numbers like "AS2303",
> TS3381"(first 2 alphabets,next 3 numbers). What i want is, i have to
[quoted text clipped - 4 lines]
> Can anyone help me?
> I am using postgresql(for your information).
Check constraints are light-weight when it comes to defining domains. You
need to enforce this rule (not a domain) via a trigger or a stored proc.
And still you can join a price with a weight, which destroys the whole idea
of a domain.
Evan
JOG - 18 Jan 2008 02:22 GMT
> > Actually, i have a need to store the numbers like "AS2303",
> > TS3381"(first 2 alphabets,next 3 numbers). What i want is, i have to
[quoted text clipped - 9 lines]
> And still you can join a price with a weight, which destroys the whole idea
> of a domain.
Does it indeed! Being british I know that the £2.00 in my pocket was
once of equivalent worth to exactly 2lb of silver - hence the currency
name. I'm thinking I might even be able to defend a natural join from
those attributes :)
But yes, I do wonder why even in Oracle one cannot define new domains
via some sort of set builder notation. Oracle does offer "object user
types", but these only have very limited constructor mechanisms (where
one might define the domain), and each instance is identified by an
OID to boot. Yuk.
> Evan
DBMS_Plumber - 18 Jan 2008 18:21 GMT
> Actually, i have a need to store the numbers like "AS2303",
> TS3381"(first 2 alphabets,next 3 numbers). What i want is, i have to
[quoted text clipped - 4 lines]
> Can anyone help me?
> I am using postgresql(for your information).
PostgreSQL was designed explicitly to handle this kind of problem.
Have a look at the entire manual section here:
http://www.postgresql.org/docs/8.1/static/extend.html
with particular attention to:
http://www.postgresql.org/docs/8.1/static/xtypes.html
and the few sections following.
What you want to do here is to define a new relational 'domain' (note:
NOT a SQL DOMAIN, which is simply a renaming of another base type).
Validity checking is done (mostly) when queries are parsed.
I am also going to guess that your new 'data type/DOMAIN' has other
requirements, such as ordering. Does "AA123" come before or after
"12345", for example?
You can define your new data type / domain and any rules that you wish
to apply over it in 'C', PL or Tcl.