This is a multi-part message in MIME format.
------_=_NextPart_001_01C8CFCF.5FD8E7EF
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
Not to say which is better or worse, I find the use
of lpad() interesting as well:
select problem_id,
lpad (cast(solution_count as varchar), 9, '0')
from problem;
Regards,
Tena Sakai
tsakai@[EMAIL PROTECTED]
Message-----
From: pgsql-sql-owner@[EMAIL PROTECTED]
on behalf of novice
Sent: Sun 6/15/2008 11:48 PM
To: A. Kretschmer
Cc: pgsql-sql@[EMAIL PROTECTED]
Re: [SQL] Results with leading zero
=20
Perfect!
Thank you very mcuh :)
2008/6/16 A. Kretschmer <andreas.kretschmer@[EMAIL PROTECTED]
>:
> am Mon, dem 16.06.2008, um 11:48:01 +1000 mailte novice folgendes:
>> I have a table
>>
>> CREATE TABLE problem (
>> problem_id integer,
>> solution_count integer
>> );
>>
>> INSERT INTO problem VALUES (1001, 4);
>> INSERT INTO problem VALUES (1012, 11);
>>
>> SELECT * from problem;
>>
>> problem_id | solution_count
>> ------------+---------------
>> 1001 | 4
>> 1012 | 11
>> (2 rows)
>>
>>
>> Is there a way I could write a query to produce the following? I =
will
>> need the leading zero for solution < 10
>>
>> problem_id | solution
>> -------------+------------
>> 1001 | 01
>> 1001 | 02
>
> My previous answer was a little bit wrong (no leading zero for =
solution
> < 10), sorry. But no problem:
>
> select problem_id, to_char(generate_Series(1,solution_count),'09') as =
solution_count from problem ;
>
>
>
> Andreas
> --
> Andreas Kretschmer
> Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
> GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
--=20
THINK BEFORE YOU PRINT - Save paper if you don't really need to print =
this.
--=20
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
------_=_NextPart_001_01C8CFCF.5FD8E7EF
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.7652.24">
<TITLE>RE: [SQL] Results with leading zero</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=3D2>Hi,<BR>
<BR>
Not to say which is better or worse, I find the use<BR>
of lpad() interesting as well:<BR>
<BR>
select problem_id,<BR>
lpad (cast(solution_count as =
varchar), 9, '0')<BR>
from problem;<BR>
<BR>
Regards,<BR>
<BR>
Tena Sakai<BR>
tsakai@[EMAIL PROTECTED]
>
<BR>
<BR>
-----Original Message-----<BR>
From: pgsql-sql-owner@[EMAIL PROTECTED]
on behalf of novice<BR>
Sent: Sun 6/15/2008 11:48 PM<BR>
To: A. Kretschmer<BR>
Cc: pgsql-sql@[EMAIL PROTECTED]
>
Subject: Re: [SQL] Results with leading zero<BR>
<BR>
Perfect!<BR>
Thank you very mcuh :)<BR>
<BR>
2008/6/16 A. Kretschmer <andreas.kretschmer@[EMAIL PROTECTED]
>
> am Mon, dem 16.06.2008, um 11:48:01 +1000 mailte novice =
folgendes:<BR>
>> I have a table<BR>
>><BR>
>> CREATE TABLE problem (<BR>
>> problem_id integer,<BR>
>> solution_count integer<BR>
>> );<BR>
>><BR>
>> INSERT INTO problem VALUES (1001, 4);<BR>
>> INSERT INTO problem VALUES (1012, 11);<BR>
>><BR>
>> SELECT * from problem;<BR>
>><BR>
>> problem_id | solution_count<BR>
>> ------------+---------------<BR>
>> 1001 =
| =
4<BR>
>> 1012 =
| =
11<BR>
>> (2 rows)<BR>
>><BR>
>><BR>
>> Is there a way I could write a query to produce the =
following? I will<BR>
>> need the leading zero for solution < 10<BR>
>><BR>
>> problem_id | solution<BR>
>> -------------+------------<BR>
>> 1001 | 01<BR>
>> 1001 | 02<BR>
><BR>
> My previous answer was a little bit wrong (no leading zero for =
solution<BR>
> < 10), sorry. But no problem:<BR>
><BR>
> select problem_id, to_char(generate_Series(1,solution_count),'09') =
as solution_count from problem ;<BR>
><BR>
><BR>
><BR>
> Andreas<BR>
> --<BR>
> Andreas Kretschmer<BR>
> Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 =
(mehr: -> Header)<BR>
> GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA <A =
HREF=3D"http://wwwkeys.de.pgp.net">http://wwwkeys.de.pgp.net</A><BR>
><BR>
> --<BR>
> Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)<BR>
> To make changes to your subscription:<BR>
> <A =
HREF=3D"http://www.postgresql.org/mailpref/pgsql-sql">http://www.postgres=
ql.org/mailpref/pgsql-sql</A><BR>
><BR>
<BR>
<BR>
<BR>
--<BR>
THINK BEFORE YOU PRINT - Save paper if you don't really need to print =
this.<BR>
<BR>
--<BR>
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)<BR>
To make changes to your subscription:<BR>
<A =
HREF=3D"http://www.postgresql.org/mailpref/pgsql-sql">http://www.postgres=
ql.org/mailpref/pgsql-sql</A><BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C8CFCF.5FD8E7EF--


|