Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: Results wit...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 6 Topic 3530 of 3703
Post > Topic >>

Re: Results with leading zero

by tsakai@[EMAIL PROTECTED] ("Tena Sakai") Jun 16, 2008 at 09:35 AM

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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lpad (cast(solution_count as =
varchar), 9, '0')<BR>
&nbsp; 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 &lt;andreas.kretschmer@[EMAIL PROTECTED]
>
&gt; am&nbsp; Mon, dem 16.06.2008, um 11:48:01 +1000 mailte novice =
folgendes:<BR>
&gt;&gt; I have a table<BR>
&gt;&gt;<BR>
&gt;&gt; CREATE TABLE problem (<BR>
&gt;&gt;&nbsp;&nbsp; problem_id&nbsp; integer,<BR>
&gt;&gt;&nbsp;&nbsp; solution_count integer<BR>
&gt;&gt;&nbsp;&nbsp; );<BR>
&gt;&gt;<BR>
&gt;&gt; INSERT INTO problem VALUES (1001, 4);<BR>
&gt;&gt; INSERT INTO problem VALUES (1012, 11);<BR>
&gt;&gt;<BR>
&gt;&gt; SELECT * from problem;<BR>
&gt;&gt;<BR>
&gt;&gt;&nbsp; problem_id | solution_count<BR>
&gt;&gt; ------------+---------------<BR>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1001 =
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 4<BR>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1012 =
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
11<BR>
&gt;&gt; (2 rows)<BR>
&gt;&gt;<BR>
&gt;&gt;<BR>
&gt;&gt; Is there a way I could write a query to produce the =
following?&nbsp; I will<BR>
&gt;&gt; need the leading zero for solution &lt; 10<BR>
&gt;&gt;<BR>
&gt;&gt;&nbsp; problem_id | solution<BR>
&gt;&gt; -------------+------------<BR>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1001 | 01<BR>
&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1001 | 02<BR>
&gt;<BR>
&gt; My previous answer was a little bit wrong (no leading zero for =
solution<BR>
&gt; &lt; 10), sorry. But no problem:<BR>
&gt;<BR>
&gt; select problem_id, to_char(generate_Series(1,solution_count),'09') =
as solution_count from problem ;<BR>
&gt;<BR>
&gt;<BR>
&gt;<BR>
&gt; Andreas<BR>
&gt; --<BR>
&gt; Andreas Kretschmer<BR>
&gt; Kontakt:&nbsp; Heynitz: 035242/47150,&nbsp;&nbsp; D1: 0160/7141639 =
(mehr: -&gt; Header)<BR>
&gt; GnuPG-ID:&nbsp;&nbsp; 0x3FFF606C, privat 0x7F4584DA&nbsp;&nbsp; <A =
HREF=3D"http://wwwkeys.de.pgp.net">http://wwwkeys.de.pgp.net</A><BR>
&gt;<BR>
&gt; --<BR>
&gt; Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)<BR>
&gt; To make changes to your subscription:<BR>
&gt; <A =
HREF=3D"http://www.postgresql.org/mailpref/pgsql-sql">http://www.postgres=
ql.org/mailpref/pgsql-sql</A><BR>
&gt;<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--
 




 6 Posts in Topic:
Results with leading zero
user.postgresql@[EMAIL PR  2008-06-16 11:48:01 
Re: Results with leading zero
mail@[EMAIL PROTECTED] (  2008-06-16 07:19:30 
Re: Results with leading zero
andreas.kretschmer@[EMAIL  2008-06-16 08:11:02 
Re: Results with leading zero
andreas.kretschmer@[EMAIL  2008-06-16 08:21:45 
Re: Results with leading zero
user.postgresql@[EMAIL PR  2008-06-16 16:48:04 
Re: Results with leading zero
tsakai@[EMAIL PROTECTED]   2008-06-16 09:35:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 16:04:13 CDT 2008.