Re: psql - user defined SQL variables

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: Grainne Reilly <greilly1(at)comcast(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: psql - user defined SQL variables
Date: 2004-08-18 05:28:17
Message-ID: 1092806896.7846.68.camel@Andrea.peacock.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Am Mi, den 18.08.2004 schrieb Grainne Reilly um 6:22:
> I am new to PostgreSQL and am porting some scripts written for MySQL over
> to psql. There is one MySQL feature which I cannot find in psql - user
> defined SQL variables. In MySQL I can use these to hold the result
> (numeric, string or null) of a select: e.g.
> select @count = count(*) from mytable;
> The @count variable now holds the result of that select, and I can use it
> in where clauses, updates, inserts etc.
> I checked out the \set psql variable but I haven't found a way to tweak it
> to give me the result of a sql statement - is there any way to do that (I'm
> using PostgreSQL version 7.4.3)?
> Thanks in advance for any suggestions,
> Grainne.

Postgres supports subselects (for update and stuff) and you can insert
like that:

INSERT INTO foo (a,b,c) SELECT a,b,c FROM ...

If thats not enough, you have a bounch of pl/*
languages to write sophisticated procedures
in the database where you have variables for
single values as well as recordsets.

Regards
Tino Wildenhain

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2004-08-18 05:48:43 Re: psql - user defined SQL variables
Previous Message Grainne Reilly 2004-08-18 04:22:27 psql - user defined SQL variables