type aliases
I can create an alias of a type like:
CREATE DOMAIN myvarchar varchar;
But I can't declare a myvarchar with a variable size, eg "mycolumn myvarchar(42)" and from what I've read this is the way it DOMAIN is supposed to work so I can't do it that way.
Is there a way to define myvarchar the way I want to? Can I use CREATE TYPE and just mirror the declaration of the underlying type?
Thanks
James
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
You probably should define your domain like this:
CREATE DOMAIN myvarchar varchar(42);
Best regards,
Behrang
http://www.behrang.org
On Sat, Feb 15, 2014 at 6:23 PM, James Harper <james.harper@bendigoit.com.au
Show quoted text
wrote:
I can create an alias of a type like:
CREATE DOMAIN myvarchar varchar;
But I can't declare a myvarchar with a variable size, eg "mycolumn
myvarchar(42)" and from what I've read this is the way it DOMAIN is
supposed to work so I can't do it that way.Is there a way to define myvarchar the way I want to? Can I use CREATE
TYPE and just mirror the declaration of the underlying type?Thanks
James
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
You probably should define your domain like this:
CREATE DOMAIN myvarchar varchar(42);
That's what I thought, so it won't do what I want. I need to be able to set the length at the time of declaration.
So suppose I wanted to implement myvarchar in C. In my _in function, how do I know how big my column declaration is? Eg if someone tries to insert 50 characters into my 42 character field, how do I get the declared length and then tell postgres that the data to be inserted is too big?
Thanks
James
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
James Harper wrote
You probably should define your domain like this:
CREATE DOMAIN myvarchar varchar(42);
That's what I thought, so it won't do what I want. I need to be able to
set the length at the time of declaration.So suppose I wanted to implement myvarchar in C. In my _in function, how
do I know how big my column declaration is? Eg if someone tries to insert
50 characters into my 42 character field, how do I get the declared length
and then tell postgres that the data to be inserted is too big?Thanks
James
IMO. You are abusing the type system to implement things that should be
defined using CHECK constraints. If indeed you are working with string I
would avoid length-limited type mods and rely on checks/constraints. There
isn't any viable alternative for numeric scale/precision type modifiers
though :(
There is no current way for a function body to examine the type modifiers of
its input, domain or otherwise.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/type-aliases-tp5792148p5792207.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
David Johnston <polobo@yahoo.com> writes:
James Harper wrote
So suppose I wanted to implement myvarchar in C. In my _in function, how
do I know how big my column declaration is? Eg if someone tries to insert
50 characters into my 42 character field, how do I get the declared length
and then tell postgres that the data to be inserted is too big?
There is no current way for a function body to examine the type modifiers of
its input, domain or otherwise.
Actually the point here is to know the required type modifier of the
*output*. Type input functions do get passed the target typmod, as a
separate argument. See varcharin() for an example.
regards, tom lane
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general