Re: Function args: TEXT -vs- VARCHAR? - Mailing list pgsql-sql

From Sergey Konoplev
Subject Re: Function args: TEXT -vs- VARCHAR?
Date
Msg-id CAL_0b1v1T7q=r1C8pV64vnNizPBPa7SWgWM5d1d6bMQoDM1BBQ@mail.gmail.com
Whole thread Raw
In response to Re: Function args: TEXT -vs- VARCHAR?  (skinner@britvault.co.uk (Craig R. Skinner))
List pgsql-sql
On Wed, Nov 13, 2013 at 5:05 AM, Craig R. Skinner
<skinner@britvault.co.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@grayhemp=# create domain text10 text constraint
text10_length_chk check (length(value) <= 10);
CREATE DOMAIN

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

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

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

[local]:5432 grayhemp@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.ru@gmail.com



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Function args: TEXT -vs- VARCHAR?
Next
From: miks87
Date:
Subject: Importing MySql dumped db into pgadmin