pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andy Shellam <andy@andycc.net>
To: pgsql-admin@postgresql.org
Subject: Number formatting
Date: Sat, 10 Jun 2006 19:15:02 +0100
Message-ID: <448B0C26.8070007@andycc.net> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <448B0C26.8070007@andycc.net>
Permalink:  ../448B0C26.8070007@andycc.net/
Also on:    postgresql.org/message-id/448B0C26.8070007@andycc.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: andy@andycc.net
  Subject: Re: Number formatting
  In-Reply-To: <448B0C26.8070007@andycc.net>
  References: <448B0C26.8070007@andycc.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox