[HACKERS] create type- similar char

2014-03-16 Thread Mohsen SM
I create one new type with CREATE TYPE command.
for my type its INTERNALLENGTH is VARIABLE .
but I want to my type behavior  similar to char and when I type this query:
CREATE TABLE tbl (col1 NEWTYPE);
then when I write this query, so it get an error for it's length:
insert into tbl values('dd');
its error is :
ERROR:  value too long for type character(1)
but my NEWTYPE don't get this error and work similar to varchar.
how I can do it?
I check for char type the bpchar() function. when I work with char type and
want to insert one word longest one character so, bpchar() called.
but for my NEWTYPE don't call the newtype() function.
how can I correct this problem?


Re: [HACKERS] create type- similar char

2014-03-16 Thread Pavel Stehule
Hello

I don't know where is a problem, but I can put a two advices

a) start by extending some known extension

b) look to source code, where and why a exception was raised. Verbose mode
can help

[pavel@localhost ~]$ psql postgres
psql (9.4devel)
Type help for help.

postgres=# \set VERBOSITY verbose
postgres=# SELECT 10/0;
ERROR:  22012: division by zero
LOCATION:  int4div, int.c:719
postgres=#


Regards

Pavel


2014-03-16 14:41 GMT+01:00 Mohsen SM mohsensoodk...@gmail.com:

 I create one new type with CREATE TYPE command.
 for my type its INTERNALLENGTH is VARIABLE .
 but I want to my type behavior  similar to char and when I type this query:
 CREATE TABLE tbl (col1 NEWTYPE);
 then when I write this query, so it get an error for it's length:
 insert into tbl values('dd');
 its error is :
 ERROR:  value too long for type character(1)
 but my NEWTYPE don't get this error and work similar to varchar.
 how I can do it?
 I check for char type the bpchar() function. when I work with char type
 and want to insert one word longest one character so, bpchar() called.
 but for my NEWTYPE don't call the newtype() function.
 how can I correct this problem?




Re: [HACKERS] create type- similar char

2014-03-16 Thread Tom Lane
Mohsen SM mohsensoodk...@gmail.com writes:
 I create one new type with CREATE TYPE command.
 for my type its INTERNALLENGTH is VARIABLE .
 but I want to my type behavior  similar to char and when I type this query:
 CREATE TABLE tbl (col1 NEWTYPE);
 then when I write this query, so it get an error for it's length:
 insert into tbl values('dd');
 its error is :
 ERROR:  value too long for type character(1)
 but my NEWTYPE don't get this error and work similar to varchar.
 how I can do it?
 I check for char type the bpchar() function. when I work with char type and
 want to insert one word longest one character so, bpchar() called.
 but for my NEWTYPE don't call the newtype() function.

It sounds like you made a length coercion cast function, but didn't
actually declare a cast based on it.  See CREATE CAST.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] CREATE TYPE similar CHAR type

2014-03-06 Thread Mohsen SM
I want use CREATE TYPE to create one type similar to char.
I want to when I create type, then my type behave similar to char:

CREATE TABLE test (oneChar char);

when I want insert one column with length1 to it, so it gets this error:
ERROR:  value too long for type character(1)

I want my type behave similar this but it behaves similar varchar type.


Re: [HACKERS] CREATE TYPE similar CHAR type

2014-03-06 Thread Thom Brown
On 6 March 2014 11:24, Mohsen SM mohsensoodk...@gmail.com wrote:

 I want use CREATE TYPE to create one type similar to char.
 I want to when I create type, then my type behave similar to char:

 CREATE TABLE test (oneChar char);

 when I want insert one column with length1 to it, so it gets this error:
 ERROR:  value too long for type character(1)

 I want my type behave similar this but it behaves similar varchar type.


If you did that, you'd have a char field padded out to fill up 10
megabytes-worth of characters.  I doubt that's what you want.

It's not clear what you want this for though.  If you want an arbitrary
number of characters, just use the text data type.
-- 
Thom


Re: [HACKERS] CREATE TYPE similar CHAR type

2014-03-06 Thread David Johnston
mohsencs wrote
 I want use CREATE TYPE to create one type similar to char.
 I want to when I create type, then my type behave similar to char:
 
 CREATE TABLE test (oneChar char);
 
 when I want insert one column with length1 to it, so it gets this error:
 ERROR:  value too long for type character(1)
 
 I want my type behave similar this but it behaves similar varchar type.

If you can get over the need for using CREATE TYPE you'll find that using
CREATE DOMAIN with a check constraint will probably meet your needs
perfectly.

David J.




--
View this message in context: 
http://postgresql.1045698.n5.nabble.com/CREATE-TYPE-similar-CHAR-type-tp5794946p5794981.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers