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

Re: varchar error

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Raul Secan <raul(at)zerosoft(dot)ro>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: varchar error
Date: 2005-06-23 15:58:57
Message-ID: 20050623155857.GB14442@wolff.to (view raw or flat)
Thread:
Lists: pgsql-php
On Thu, Jun 23, 2005 at 11:18:45 +0300,
  Raul Secan <raul(at)zerosoft(dot)ro> 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.

In response to

pgsql-php by date

Next:From: Nick StoneDate: 2005-06-30 09:35:06
Subject: Pqsocket not implemented in PHP
Previous:From: Marco ColomboDate: 2005-06-23 11:29:07
Subject: Re: varchar error

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