CREATE TYPE similar CHAR type

Started by Mohsen SMalmost 12 years ago3 messages
#1Mohsen SM
mohsensoodkhah@gmail.com

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 length>1 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.

#2Thom Brown
thom@linux.com
In reply to: Mohsen SM (#1)
Re: CREATE TYPE similar CHAR type

On 6 March 2014 11:24, Mohsen SM <mohsensoodkhah@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 length>1 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

#3David Johnston
polobo@yahoo.com
In reply to: Mohsen SM (#1)
Re: CREATE TYPE similar CHAR type

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 length>1 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