Skip site navigation (1) Skip section navigation (2)

Re: Simple Accumulating Number Loop?

From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: Ubence Quevedo <r0d3nt(at)pacbell(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: Simple Accumulating Number Loop?
Date: 2005-12-29 23:36:02
Message-ID: 43B472E2.7040008@presinet.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novice
Ubence Quevedo wrote:
> A friend of mine has created this simple accumulating
> loop query for MS SQL 2k5 Express Edition.  I am
> trying to reproduce the same results with PostgreSQL
> 8.1, but am not able to find much useful help on how
> to properly set up a variable of both int and char. 
> The PostgreSQL documentation is great if you have an
> idea of what you are doing, but I'm still really new
> to PostgreSQL.  If someone can just point out some
> hints or clarifications as to wether to use the SET
> command or the psql \set command.  Below is the query
> in question.
> 
> Many thanx to any that can help.
> 
> -Ubence
> 
> declare @variableint int
> declare @desc char (50)
> set @variableint = 0
> create table counter (countid int , description
> varchar(50))
> while @variableint < 500
> begin
> set @variableint = @variableint + 1
> set @desc = 'The Counter is Now' +' '+ cast
> (@variableint as char(50))
> insert into counter values (@variableint,@desc)
> end
> select * from counter
> 

look for FOR or WHILE loops
http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html

In response to

pgsql-novice by date

Next:From: Oliver ElphickDate: 2005-12-29 23:37:11
Subject: Re: ?linux distro?
Previous:From: Ubence QuevedoDate: 2005-12-29 23:26:07
Subject: Simple Accumulating Number Loop?

pgsql-general by date

Next:From: Ken WinterDate: 2005-12-30 04:13:07
Subject: In processing DDL, when does pg_catalog get updated?
Previous:From: Ubence QuevedoDate: 2005-12-29 23:26:07
Subject: Simple Accumulating Number Loop?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group