Number formatting

From: Andy Shellam <andy(at)andycc(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Number formatting
Date: 2006-06-10 18:15:02
Message-ID: 448B0C26.8070007@andycc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi,

Simple question, which is probably something obvious I'm missing. If
anyone can tell me better how to do what I'm doing, go for it!

This is for a billing system, and I want PostgreSQL to generate unique
reference numbers for each invoice that is something more meaningful
than 1, 2, 3 etc.

So, what I'm trying to do is use a primary key to generate invoice
numbers such as "INV0000001", "INV0000002" etc. Obviously a sequence
generates the increments, but when I try formatting it, it adds a space
at the beginning of the number. Here's the "default value" for the
primary key field:

(('INV'::text ||
to_char((nextval('customer_customer_id_seq'::regclass))::integer,
'0000000'::text)))::character varying

However what I end up with is: "INV 0000012"

If I take the "INV" portion out, and simply try and format the sequence
generated, I still get the space added: " 0000013"

(to_char((nextval('customer_customer_id_seq'::regclass))::integer,
'0000000'::text))::character varying

The field is defined as a varchar(10), which allows the 3-digit "INV",
and 7 numeric digits. I have tried defining it as char(10) but still
get the same.

This is on PostgreSQL 8.1.4, Windows XP.

Thanks

Andy

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2006-06-10 18:25:00 Re: problem with installing postgresql
Previous Message Christopher Browne 2006-06-10 13:11:36 Re: problem with installing postgresql