From raul@zerosoft.ro Thu Jun 23 08:19:13 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B1CA852812 for ; Thu, 23 Jun 2005 05:19:13 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78480-09 for ; Thu, 23 Jun 2005 08:19:04 +0000 (GMT) Received: from mail.zerosoft.ro (main.zerosoft.ro [85.186.32.196]) by svr1.postgresql.org (Postfix) with ESMTP id 17F3852973 for ; Thu, 23 Jun 2005 05:19:00 -0300 (ADT) Received: from 192.168.16.10 by mail.zerosoft.ro ([192.168.16.1] running VPOP3) with SMTP for ; Thu, 23 Jun 2005 11:18:45 +0300 Message-ID: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> Reply-To: "Raul Secan" From: "Raul Secan" To: Subject: varchar error Date: Thu, 23 Jun 2005 11:18:45 +0300 Organization: ZEROSOFT MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000A_01C577E5.51E02F70" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Server: VPOP3 V1.4.5 - Registered to: ZeroSoft X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.078 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, HTML_60_70, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200506/19 X-Sequence-Number: 3178 This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C577E5.51E02F70 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello, I just have this: CREATE TABLE test ( mytext varchar(5) ) WITHOUT OIDS; If I put a string with more than 5 chars in mytext, I receive an error, = regarding the wrong lenght of the string. In MySQL I know that the string is automatically reduced to the number = of char allowed by the column, even if I insert a longer string. I don't want to do this from PHP, and I was wandering how this can be = done in PostreSQL? Maybe in CREATE TABLE definition? Cheers, Raul. ------=_NextPart_000_000A_01C577E5.51E02F70 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello, I just have=20 this:
 
CREATE TABLE test=20 (
    mytext varchar(5)
) WITHOUT = OIDS;
 
If I put a string = with more than 5=20 chars in mytext, I receive an error, regarding the wrong lenght of the=20 string.
 
In MySQL I know that = the string is=20 automatically reduced to the number of char allowed by the column, even = if I=20 insert a longer string.
 
I don't want to do = this from PHP,=20 and I was wandering how this can be done in PostreSQL? Maybe in = CREATE=20 TABLE definition?
 
Cheers,=20 Raul.
------=_NextPart_000_000A_01C577E5.51E02F70-- From volkan.yazici@gmail.com Thu Jun 23 08:33:55 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3403052923 for ; Thu, 23 Jun 2005 05:33:55 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83625-02 for ; Thu, 23 Jun 2005 08:33:46 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196]) by svr1.postgresql.org (Postfix) with ESMTP id 2F710528D9 for ; Thu, 23 Jun 2005 05:33:45 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 69so278750wra for ; Thu, 23 Jun 2005 01:33:47 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=NRpLox8bklgiN2unfXGG6+FN6khrlo1gy5N7InqwwCPDTSGS4DZyKYPqu3cCBgBLxQs9WEMRz/iZdImgv9EDXBdNSlKfRieTxf0WuDdp+JA8g9BIJd/cz7HTGnWkvS0AO56/Brbm/yQI/Y/A7AlP4qLOs1MOj4MOEG7Wdlzi+ok= Received: by 10.54.145.8 with SMTP id s8mr1007216wrd; Thu, 23 Jun 2005 01:33:47 -0700 (PDT) Received: by 10.54.30.45 with HTTP; Thu, 23 Jun 2005 01:33:47 -0700 (PDT) Message-ID: <7104a73705062301332ca4bb4d@mail.gmail.com> Date: Thu, 23 Jun 2005 11:33:47 +0300 From: Volkan YAZICI Reply-To: Volkan YAZICI To: Raul Secan Subject: Re: varchar error Cc: pgsql-php@postgresql.org In-Reply-To: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.127 tagged_above=0 required=5 tests=AWL, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200506/20 X-Sequence-Number: 3179 Hi, On 6/23/05, Raul Secan wrote: > CREATE TABLE test ( > mytext varchar(5) > ) WITHOUT OIDS;=20 > =20 > If I put a string with more than 5 chars in mytext, I receive an error, > regarding the wrong lenght of the string.=20 > =20 > In MySQL I know that the string is automatically reduced to the number of > char allowed by the column, even if I insert a longer string. I don't think that it's the function of database to manipulate the input. > I don't want to do this from PHP, and I was wandering how this can be don= e > in PostreSQL? Maybe in CREATE TABLE definition?=20 IMHO, you can create an insert (and update) procedure (like my_insert() and my_update()) with using substr() [1] function. [1] www.postgresql.org/docs/8.0/interactive/functions-string.html Regards. From anthony@kaartjeposten.nl Thu Jun 23 08:41:00 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 555FD52812 for ; Thu, 23 Jun 2005 05:41:00 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81936-08 for ; Thu, 23 Jun 2005 08:40:54 +0000 (GMT) Received: from kaartjeposten.nl (unknown [82.192.72.223]) by svr1.postgresql.org (Postfix) with ESMTP id 4B6DC5295A for ; Thu, 23 Jun 2005 05:40:53 -0300 (ADT) Received: from [172.16.77.10] (p508FCE44.dip.t-dialin.net [::ffff:80.143.206.68]) (AUTH: LOGIN anthony@kaartjeposten.nl) by kaartjeposten.nl with esmtp; Thu, 23 Jun 2005 10:40:54 +0200 id 0003FEDB.42BA7596.00004419 Received-SPF: unknown (Address does not pass the Sender Policy Framework) SPF=HELO; sender=[172.16.77.10]; remoteip=::ffff:80.143.206.68; remotehost=p508FCE44.dip.t-dialin.net; helo=[172.16.77.10]; receiver=kaartjeposten.nl; Received-SPF: none (Address does not pass the Sender Policy Framework) SPF=MAILFROM; sender=anthony@kaartjeposten.nl; remoteip=::ffff:80.143.206.68; remotehost=p508FCE44.dip.t-dialin.net; helo=[172.16.77.10]; receiver=kaartjeposten.nl; Message-ID: <42BA7593.2030803@kaartjeposten.nl> Date: Thu, 23 Jun 2005 10:40:51 +0200 From: Anthony van den Berg Reply-To: anthony@kaartjeposten.nl Organization: Kaartjeposten.nl User-Agent: Mozilla Thunderbird 1.0.2-1.3.3 (X11/20050513) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Raul Secan Cc: pgsql-php@postgresql.org Subject: Re: varchar error References: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> In-Reply-To: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> Content-Type: multipart/alternative; boundary="------------010607010608060009040805" Received-SPF: none (Address does not pass the Sender Policy Framework) SPF=FROM; sender=anthony@kaartjeposten.nl; remoteip=::ffff:80.143.206.68; remotehost=p508FCE44.dip.t-dialin.net; helo=[172.16.77.10]; receiver=kaartjeposten.nl; X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.096 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: X-Archive-Number: 200506/21 X-Sequence-Number: 3180 This is a multi-part message in MIME format. --------------010607010608060009040805 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit you might try a trigger! Raul Secan wrote: > Hello, I just have this: > > CREATE TABLE test ( > mytext varchar(5) > ) WITHOUT OIDS; > > If I put a string with more than 5 chars in mytext, I receive an > error, regarding the wrong lenght of the string. > > In MySQL I know that the string is automatically reduced to the number > of char allowed by the column, even if I insert a longer string. > > I don't want to do this from PHP, and I was wandering how this can be > done in PostreSQL? Maybe in CREATE TABLE definition? > > Cheers, Raul. -- Kaartjeposten.nl Molukkenstraat 80 / 7512 XT Enschede * info@kaartjeposten.nl / msn. kaartjeposten@hotmail.com i. www.kaartjeposten.nl / t. 06 - 28 13 88 57 Nu ook voor uw verjaardagkalenders --------------010607010608060009040805 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit you might try a trigger!


Raul Secan wrote:
Hello, I just have this:
 
CREATE TABLE test (
    mytext varchar(5)
) WITHOUT OIDS;
 
If I put a string with more than 5 chars in mytext, I receive an error, regarding the wrong lenght of the string.
 
In MySQL I know that the string is automatically reduced to the number of char allowed by the column, even if I insert a longer string.
 
I don't want to do this from PHP, and I was wandering how this can be done in PostreSQL? Maybe in CREATE TABLE definition?
 
Cheers, Raul.

--
kaartjeposten

Kaartjeposten.nl
Molukkenstraat 80 / 7512 XT  Enschede
* info@kaartjeposten.nl / msn. kaartjeposten@hotmail.com
i. www.kaartjeposten.nl / t. 06 - 28 13 88 57
Nu ook voor uw verjaardagkalenders


--------------010607010608060009040805-- From s.gnanavel@inbox.com Thu Jun 23 08:53:23 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BFD0D52838 for ; Thu, 23 Jun 2005 05:53:23 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86645-03 for ; Thu, 23 Jun 2005 08:53:15 +0000 (GMT) Received: from WM12.inbox.com (wm12.inbox.com [208.50.6.12]) by svr1.postgresql.org (Postfix) with SMTP id 8FF66528BB for ; Thu, 23 Jun 2005 05:53:13 -0300 (ADT) Received: from inbox.com (127.0.0.1:25) by inbox.com with [InBox.Com ESMTP Server] id <506230001266.WM12> for from ; Thu, 23 Jun 2005 12:53:10 AM -0800 Mime-Version: 1.0 Date: Thu, 23 Jun 2005 00:53:09 -0800 Message-ID: <5A50EF07DAA.00000851s.gnanavel@inbox.com> From: Gnanavel Shanmugam Subject: Re: varchar error To: Raul Secan , pgsql-php@postgresql.org In-Reply-To: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> X-Mailer: IBISIT WebMail Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.612 tagged_above=0 required=5 tests=AWL, HTML_60_70, HTML_MESSAGE, MIME_HTML_ONLY X-Spam-Level: X-Archive-Number: 200506/22 X-Sequence-Number: 3181 <=21DOCTYPE HTML PUBLIC =22-//W3C//DTD HTML 4.0 = Transitional//EN=22>
try with either Rule or Trigger.
 
with regards,
S.Gnanavel


-----Original Message-----
From: = raul=40zerosoft.ro
Sent: Thu, 23 Jun 2005 11:18:45 = +0300
To: pgsql-php=40postgresql.org
Subject: = =5BPHP=5D varchar error

Hello, I just have=20 this:
 
CREATE TABLE test=20 (
    mytext varchar(5)
) WITHOUT OIDS;
 
If = I put a string with more than 5=20 chars in mytext, I receive an error, regarding the wrong lenght of the=20 string.
 
In = MySQL I know that the string is=20 automatically reduced to the number of char allowed by the column, even if = I=20 insert a longer string.
 
I = don't want to do this from PHP,=20 and I was wandering how this can be done in PostreSQL? Maybe in = CREATE=20 TABLE definition?
 
Cheers,=20 Raul.
= From pgsql@esiway.net Thu Jun 23 11:27:06 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E89EA5284D for ; Thu, 23 Jun 2005 08:27:06 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12907-09 for ; Thu, 23 Jun 2005 11:27:00 +0000 (GMT) Received: from Nazgul.esiway.net (Nazgul.esiway.net [193.194.16.154]) by svr1.postgresql.org (Postfix) with ESMTP id 8FED7528A8 for ; Thu, 23 Jun 2005 08:26:56 -0300 (ADT) Received: from Megathlon.ESI (Ghost.esi.it [193.194.16.225]) by Nazgul.esiway.net (8.13.1/8.13.1) with ESMTP id j5NBQv9X027987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 23 Jun 2005 13:26:57 +0200 Received: from Frodo.esi (Frodo.ESI [10.10.10.13]) (user=marco mech=CRAM-MD5 bits=0) by Megathlon.ESI (8.12.11/8.12.11) with ESMTP id j5NBQvID019048 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Thu, 23 Jun 2005 13:26:57 +0200 Subject: Re: varchar error From: Marco Colombo To: Raul Secan Cc: pgsql-php@postgresql.org In-Reply-To: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> References: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> Content-Type: text/plain Date: Thu, 23 Jun 2005 13:29:07 +0200 Message-Id: <1119526147.24016.208.camel@Frodo.esi> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 (2.0.4-4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200506/23 X-Sequence-Number: 3182 On Thu, 2005-06-23 at 11:18 +0300, Raul Secan wrote: > Hello, I just have this: > > CREATE TABLE test ( > mytext varchar(5) > ) WITHOUT OIDS; > > If I put a string with more than 5 chars in mytext, I receive an > error, regarding the wrong lenght of the string. > > In MySQL I know that the string is automatically reduced to the number > of char allowed by the column, even if I insert a longer string. > > I don't want to do this from PHP, and I was wandering how this can be > done in PostreSQL? Maybe in CREATE TABLE definition? > > Cheers, Raul. The job of the database is to accept valid data and to refuse invalid ones, not to silently convert invalid data into a valid form. While it is possible to do that conversion in PostgreSQL, I suggest you either reconsider doing it in the application (the place it belongs to), or think again about the schema (maybe storing the whole string). BTW, you can also truncate the string at insert time, just change: INSERT INTO test (mytext) VALUES ('alongstring'); into: INSERT INTO test (mytext) VALUES (substring('alongstring' for 5)); Here it is, in action: marco=# CREATE TABLE test (mytext varchar(5)) WITHOUT OIDS; CREATE TABLE marco=# INSERT INTO test (mytext) VALUES ('alongstring'); ERROR: value too long for type character varying(5) marco=# INSERT INTO test (mytext) VALUES (substring('alongstring' for 5)); INSERT 0 1 marco=# SELECT * FROM test; mytext -------- along (1 row) Of course, you have to do that on every UPDATE, too. If that's what you want to achieve, I find it much more readable to do the substring() or the PHP equivalent explicitly, rather than relying on some implicit RULE or TRIGGER (or worse, on a database that silently truncates it). For sure I get puzzled when SELECT returns 'along' after I do INSERT 'alongstring'. Think about consistency. .TM. -- ____/ ____/ / / / / Marco Colombo ___/ ___ / / Technical Manager / / / ESI s.r.l. _____/ _____/ _/ Colombo@ESI.it From bruno@wolff.to Thu Jun 23 15:59:16 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 171B15295C for ; Thu, 23 Jun 2005 12:59:16 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72281-09 for ; Thu, 23 Jun 2005 15:59:10 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id 10AAF5293C for ; Thu, 23 Jun 2005 12:59:09 -0300 (ADT) Received: (qmail 15677 invoked by uid 500); 23 Jun 2005 15:58:57 -0000 Date: Thu, 23 Jun 2005 10:58:57 -0500 From: Bruno Wolff III To: Raul Secan Cc: pgsql-php@postgresql.org Subject: Re: varchar error Message-ID: <20050623155857.GB14442@wolff.to> Mail-Followup-To: Bruno Wolff III , Raul Secan , pgsql-php@postgresql.org References: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000d01c577cc$2c9c1f30$0a10a8c0@zerosoft.ro> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/24 X-Sequence-Number: 3183 On Thu, Jun 23, 2005 at 11:18:45 +0300, Raul Secan wrote: > Hello, I just have this: > > CREATE TABLE test ( > mytext varchar(5) > ) WITHOUT OIDS; > > If I put a string with more than 5 chars in mytext, I receive an error, regarding the wrong lenght of the string. > > In MySQL I know that the string is automatically reduced to the number of char allowed by the column, even if I insert a longer string. > > I don't want to do this from PHP, and I was wandering how this can be done in PostreSQL? Maybe in CREATE TABLE definition? The way to do this is to use the substring function to do this. You can extract the first 5 characters of the string you are supplied.