pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedvariables in procedures
3+ messages / 3 participants
[nested] [flat]
* variables in procedures
@ 2001-11-30 13:43 Martín Marqués <martin@bugs.unl.edu.ar>
2001-11-30 17:09 ` Re: variables in procedures Josh Berkus <josh@agliodbs.com>
2001-11-30 17:34 ` Re: variables in procedures Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 2 replies; 3+ messages in thread
From: Martín Marqués @ 2001-11-30 13:43 UTC (permalink / raw)
To: pgsql-sql
How can I distinguish between the name and the value of a variable?
Example:
CREATE FUNCTION test(VARCHAR) RETURNS INTEGER AS '
DECLARE
col1 ALIAS FOR $1
BEGIN
select col1 from tab where col1=´´col1´´;
END;
´ LANGUAGE 'plpgsql';
Is my doubt understood?
--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués | mmarques@unl.edu.ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: variables in procedures
2001-11-30 13:43 variables in procedures Martín Marqués <martin@bugs.unl.edu.ar>
@ 2001-11-30 17:09 ` Josh Berkus <josh@agliodbs.com>
1 sibling, 0 replies; 3+ messages in thread
From: Josh Berkus @ 2001-11-30 17:09 UTC (permalink / raw)
To: Martín Marqués <martin@bugs.unl.edu.ar>; pgsql-sql
Martin,
> How can I distinguish between the name and the value of a variable?
You need to name your variables something *different* from your column
names. Otherwise, you will get unexpected errors.
A practice I usually follow is prefixing my column-substitiution
variables with "v_". This allows me, and the PL/pgSQL parser, to keep
the variables straight from the columns. I also need to fix your
procedure in a couple of places. Thus:
CREATE FUNCTION test(VARCHAR) RETURNS INTEGER AS '
DECLARE
v_col1 ALIAS FOR $1;
v_result INT;
BEGIN
select col1 INTO v_result
from tab where col1 = v_col1;
RETURN v_result;
END;
´ LANGUAGE 'plpgsql';
Other SQL-procedural languages (e.g. Transact-SQL) force you to prefix
your variables with special characters. In PL/pgSQL, it's up to you to
maintain consistency.
-Josh Berkus
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: variables in procedures
2001-11-30 13:43 variables in procedures Martín Marqués <martin@bugs.unl.edu.ar>
@ 2001-11-30 17:34 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
1 sibling, 0 replies; 3+ messages in thread
From: Stephan Szabo @ 2001-11-30 17:34 UTC (permalink / raw)
To: Martín Marqués <martin@bugs.unl.edu.ar>; +Cc: pgsql-sql
On Fri, 30 Nov 2001, [iso-8859-1] Martín Marqués wrote:
> How can I distinguish between the name and the value of a variable?
>
> Example:
>
> CREATE FUNCTION test(VARCHAR) RETURNS INTEGER AS '
>
> DECLARE
> col1 ALIAS FOR $1
> BEGIN
> select col1 from tab where col1=´´col1´´;
> END;
> ´ LANGUAGE 'plpgsql';
>
>
> Is my doubt understood?
AFAIK you don't distinguish, you'll probably need to name
the variable something else.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-11-30 17:34 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-11-30 13:43 variables in procedures Martín Marqués <martin@bugs.unl.edu.ar>
2001-11-30 17:09 ` Josh Berkus <josh@agliodbs.com>
2001-11-30 17:34 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
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