Skip site navigation (1) Skip section navigation (2)

Re: insert в varchar

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Genix <genix(at)list(dot)ru>
Cc: pgsql-ru-general <pgsql-ru-general(at)postgresql(dot)org>
Subject: Re: insert в varchar
Date: 2005-12-06 13:48:28
Message-ID: Pine.GSO.4.63.0512061647480.13553@ra.sai.msu.su (view raw or flat)
Thread:
Lists: pgsql-ru-general
On Tue, 6 Dec 2005, Genix wrote:

> Приветствую!
>
> Подскажите, можно ли настроить PgSQL таким образом, чтобы при insert'е в поле 
> varchar(XX) строки длиннее    XX+1 не возникало ошибки? Т.е. чтобы она просто 
> обрезалась до XX символов.

обрезай сам. substr() тебе поможет

>
> Спасибо.
>
>

 	Regards,
 		Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83
>From pgsql-ru-general-owner(at)postgresql(dot)org  Tue Dec  6 10:00:11 2005
X-Original-To: pgsql-ru-general-postgresql(dot)org(at)localhost(dot)postgresql(dot)org
Received: from localhost (av.hub.org [200.46.204.144])
	by postgresql.org (Postfix) with ESMTP id AE7179DCBE2
	for <pgsql-ru-general-postgresql(dot)org(at)localhost(dot)postgresql(dot)org>; Tue,  6 Dec 2005 10:00:08 -0400 (AST)
Received: from postgresql.org ([200.46.204.71])
 by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
 with ESMTP id 14856-03
 for <pgsql-ru-general-postgresql(dot)org(at)localhost(dot)postgresql(dot)org>;
 Tue,  6 Dec 2005 10:00:07 -0400 (AST)
X-Greylist: from auto-whitelisted by SQLgrey-
Received: from rex.antar.bryansk.ru (rex.online.bryansk.ru [80.237.18.81])
	by postgresql.org (Postfix) with ESMTP id 0016F9DCAC0
	for <pgsql-ru-general(at)postgresql(dot)org>; Tue,  6 Dec 2005 09:59:55 -0400 (AST)
Received: from [195.239.214.85] (helo=dyatel.antar.bryansk.ru)
	by rex.antar.bryansk.ru with esmtp (Exim 4.54 (FreeBSD))
	id 1EjdMM-00054A-Ld; Tue, 06 Dec 2005 16:59:58 +0300
Received: from fduch by dyatel.antar.bryansk.ru with local (Exim 4.60 (FreeBSD))
	(envelope-from <fduch(at)dyatel(dot)antar(dot)bryansk(dot)ru>)
	id 1EjdMM-000KHQ-HC; Tue, 06 Dec 2005 16:59:58 +0300
Date: Tue, 6 Dec 2005 16:59:58 +0300
From: "Alexander M. Pravking" <fduch(at)antar(dot)bryansk(dot)ru>
To: Genix <genix(at)list(dot)ru>
Cc: pgsql-ru-general <pgsql-ru-general(at)postgresql(dot)org>
Subject: Re: =?koi8-r?Q?insert_?=
Message-ID: <20051206135958(dot)GJ16326(at)dyatel(dot)antar(dot)bryansk(dot)ru>
References: <43959121(dot)4080005(at)list(dot)ru>
Mime-Version: 1.0
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <43959121(dot)4080005(at)list(dot)ru>
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=1.543 required=5 tests=[SUBJECT_ENCODED_TWICE=1.543]
X-Spam-Score: 1.543
X-Spam-Level: *
X-Archive-Number: 200512/10
X-Sequence-Number: 467

On Tue, Dec 06, 2005 at 04:24:49PM +0300, Genix wrote:
> Подскажите, можно ли настроить PgSQL таким образом, чтобы при insert'е в 
> поле varchar(XX) строки длиннее    XX+1 не возникало ошибки? Т.е. чтобы 
> она просто обрезалась до XX символов.

Если уж лень делать substr в запросах, то наиболее простым мне видится
следующее: сделать поле text вместо varchar(XX) и повесить триггер
BEFORE INSERT OR UPDATE, который будет обрезать поле до нужного размера.


-- 
Fduch M. Pravking

In response to

pgsql-ru-general by date

Next:From: Andrey N. OktyabrskiDate: 2005-12-06 14:13:38
Subject: Re: insert в varchar
Previous:From: GenixDate: 2005-12-06 13:24:49
Subject: insert в varchar

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group