Re: Function args: TEXT -vs- VARCHAR?

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: "Craig R(dot) Skinner" <skinner(at)britvault(dot)co(dot)uk>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Function args: TEXT -vs- VARCHAR?
Date: 2013-11-14 07:41:35
Message-ID: CAL_0b1v1T7q=r1C8pV64vnNizPBPa7SWgWM5d1d6bMQoDM1BBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Nov 13, 2013 at 5:05 AM, Craig R. Skinner
<skinner(at)britvault(dot)co(dot)uk> wrote:
> On 2013-11-12 Tue 19:07 PM |, Sergey Konoplev wrote:
>> There is a good article about
>> this [1]http://www.depesz.com/2010/03/02/charx-vs-varcharx-vs-varchar-v
>> s-text/.
>
> It is an interesting item about table column types, not function arguments.

Well, actually if you use doman+constraint it will work with function arguments:

[local]:5432 grayhemp(at)grayhemp=# create domain text10 text constraint
text10_length_chk check (length(value) <= 10);
CREATE DOMAIN

[local]:5432 grayhemp(at)grayhemp=# create or replace function f(t
text10) returns void language 'plpgsql' as $$ begin raise info '%', t;
return; end $$;
CREATE FUNCTION

[local]:5432 grayhemp(at)grayhemp=# select '12345678900'::text10;
ERROR: value for domain text10 violates check constraint "text10_length"

[local]:5432 grayhemp(at)grayhemp=# select f('1234567890');
INFO: 1234567890

[local]:5432 grayhemp(at)grayhemp=# select f('12345678900');
ERROR: value for domain text10 violates check constraint "text10_length_chk"

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message miks87 2013-11-24 15:49:17 Importing MySql dumped db into pgadmin
Previous Message Tom Lane 2013-11-13 18:31:13 Re: Function args: TEXT -vs- VARCHAR?