Re: Chante domain type - Postgres 9.2

Поиск
Список
Период
Сортировка
От Michael Sheaver
Тема Re: Chante domain type - Postgres 9.2
Дата
Msg-id 2F4473F3-3AA3-4233-AB9F-6B528A3DC20D@me.com
обсуждение исходный текст
Ответ на Re: Chante domain type - Postgres 9.2  (Jan de Visser <jan@de-visser.net>)
Ответы Re: Chante domain type - Postgres 9.2  (Rakesh Kumar <rakeshkumar464@outlook.com>)
Re: Chante domain type - Postgres 9.2  (Michael Sheaver <msheaver@me.com>)
Список pgsql-general
I have done some research after converting my database from MySQL 5.6 to PostgreSQL 9.6 (the best move I have ever made), and the consensus I found can be summed up as:
1.  Never, neve, never use VARCHAR or even CHAR
2. Always always, always use TEXT

Unless, that is, you have some kind of edge case. This may require a little work upfront, but it will save you from a TON of grief down the road.


On Sep 26, 2016, at 8:29 AM, Jan de Visser <jan@de-visser.net> wrote:

On 2016-09-26 1:15 AM, Gavin Flower wrote:

On 26/09/16 17:58, Patrick B wrote:
Hi guys,

I've got this domain:

   CREATE DOMAIN public.a_city
     AS character varying(80)
     COLLATE pg_catalog."default";


And I need to increase the type from character varying(80) to character varying(255).

How can I do that? didn't find info about it. I'm using Postgres 9.2

Thanks!
Patrick

Why not simply use the 'text' data type?

To change the data type on a column you can use:
ALTER [ COLUMN ] /column_name/ [ SET DATA ] TYPE /data_type/ [ COLLATE /collation/ ] [ USING /expression/ ]

see:
https://www.postgresql.org/docs/9.2/static/sql-altertable.html


Note that 9.5 is the latest version of pg, with 9.6 being released very soon!


Cheers,
Gavin


So I guess the answer to the question is:
- Find all occurrences of a_city
- Change the type of those columns to text (or varchar(80))
- Drop the domain
- Recreate with the proper definition. I agree with Gavin that text is a better choice. Experience has taught me that server side size constraint are more trouble than they're worth and that size constraints are better handled on the client side.
- Change the type of the columns back to the domain.





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

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

Предыдущее
От: Jan de Visser
Дата:
Сообщение: Re: Chante domain type - Postgres 9.2
Следующее
От: Rakesh Kumar
Дата:
Сообщение: Re: Chante domain type - Postgres 9.2