pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Variables in PSQL
2+ messages / 2 participants
[nested] [flat]

* Variables in PSQL
@ 2002-07-08 13:24 Roger Mathis <traderx@gmx.ch>
  1970-01-01 00:00 ` Re: Variables in PSQL Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 1 reply; 2+ messages in thread

From: Roger Mathis @ 2002-07-08 13:24 UTC (permalink / raw)
  To: pgsql-sql

Hi

I'm trying to declare a variable in PostgreSQL, so I can save some values in
it. After, I want to calculate with this variable.
For example:

declare vp integer;
select price into :vp from article where anr = 1;
vp := vp + 1;
update article set price = :vp where anr = 1;

Is there a posibility to do that without creating a funktion?
Thanks for your answers.

CU Roger







^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Variables in PSQL
  2002-07-08 13:24 Variables in PSQL Roger Mathis <traderx@gmx.ch>
@ 1970-01-01 00:00 ` Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 0 replies; 2+ messages in thread

From: Christoph Haller @ 1970-01-01 00:00 UTC (permalink / raw)
  To: traderx@gmx.ch; +Cc: pgsql-sql

> 
> I'm trying to declare a variable in PostgreSQL, so I can save some values in
> it. After, I want to calculate with this variable.
> For example:
> 
> declare vp integer;
> select price into :vp from article where anr = 1;
> vp := vp + 1;
> update article set price = :vp where anr = 1;

AFAIK, you can do stuff like this only within a function. 
> 
> Is there a posibility to do that without creating a funktion?

What about 
update article set price =
 (select price + 1 from article where anr = 1)
where anr = 1; 

Regards, Christoph 



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-07-08 13:24 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-08 13:24 Variables in PSQL Roger Mathis <traderx@gmx.ch>
1970-01-01 00:00 ` Christoph Haller <ch@rodos.fzk.de>

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