pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedNumber formatting
3+ messages / 2 participants
[nested] [flat]
* Number formatting
@ 2006-06-10 18:15 Andy Shellam <andy@andycc.net>
2006-06-10 18:28 ` Re: Number formatting Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shellam @ 2006-06-10 18:15 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Number formatting
2006-06-10 18:15 Number formatting Andy Shellam <andy@andycc.net>
@ 2006-06-10 18:28 ` Michael Fuhr <mike@fuhr.org>
2006-06-10 18:32 ` Re: Number formatting Andy Shellam <andy@andycc.net>
0 siblings, 1 reply; 3+ messages in thread
From: Michael Fuhr @ 2006-06-10 18:28 UTC (permalink / raw)
To: Andy Shellam <andy@andycc.net>; +Cc: pgsql-admin
On Sat, Jun 10, 2006 at 07:15:02PM +0100, Andy Shellam wrote:
> 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.
The FM modifier suppresses padding spaces.
http://www.postgresql.org/docs/8.1/interactive/functions-formatting.html#FUNCTIONS-FORMATTING-DATETI...
test=> SELECT 'INV' || to_char(123, 'FM0000000');
?column?
------------
INV0000123
(1 row)
--
Michael Fuhr
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Number formatting
2006-06-10 18:15 Number formatting Andy Shellam <andy@andycc.net>
2006-06-10 18:28 ` Re: Number formatting Michael Fuhr <mike@fuhr.org>
@ 2006-06-10 18:32 ` Andy Shellam <andy@andycc.net>
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shellam @ 2006-06-10 18:32 UTC (permalink / raw)
To: Michael Fuhr <mike@fuhr.org>; +Cc: pgsql-admin
Perfect
Thanks Michael :-)
Andy
Michael Fuhr wrote:
> On Sat, Jun 10, 2006 at 07:15:02PM +0100, Andy Shellam wrote:
>> 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.
>
> The FM modifier suppresses padding spaces.
>
> http://www.postgresql.org/docs/8.1/interactive/functions-formatting.html#FUNCTIONS-FORMATTING-DATETI...
>
> test=> SELECT 'INV' || to_char(123, 'FM0000000');
> ?column?
> ------------
> INV0000123
> (1 row)
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-06-10 18:32 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-10 18:15 Number formatting Andy Shellam <andy@andycc.net>
2006-06-10 18:28 ` Michael Fuhr <mike@fuhr.org>
2006-06-10 18:32 ` Andy Shellam <andy@andycc.net>
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