Re: Leading Zeros - Mailing list pgsql-novice

From David
Subject Re: Leading Zeros
Date
Msg-id 20050804043218.GA5207@localhost.localdomain
Whole thread Raw
In response to Re: Leading Zeros  (<operationsengineer1@yahoo.com>)
List pgsql-novice
On Wed, Aug 03, 2005 at 08:57:20PM -0700, operationsengineer1@yahoo.com wrote:
> --- Gordon Haverland <ghaverla@shaw.ca> wrote:
>
> > On Wednesday 03 August 2005 15:23, operationsengineer1@yahoo.com wrote:

> > > can i use pgsql to force th einput of leading zeros?

> > > i have an application that enters serial numbers within a range,
> > > eg, 00001 to 00003.

> > Use a string type, but only allow certain characters.

> Gord,
>
> if i do that, though, i think i'm unable to increment
> the number string in php.  the user inputs the
> beginning and ending s/n only.  i use php to create
> and enter the other s/ns.  can i still increment a
> number string using i++?

You probably could do it as a string in php, but I think I'd use it as a
decimal in php, and then use a printf() statement when you do an insert.

Like this example (where mycol is of some string type):

<?php
    $num = 12;

    $sql = "INSERT INTO table (mycol), VALUES('" .
            printf("%06d",$num) . "')";
?>

pgsql-novice by date:

Previous
From:
Date:
Subject: Re: Leading Zeros
Next
From: Dane Ensign
Date:
Subject: string concatenation errors