Re: PL/pgSQL 'i = i + 1' Syntax

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Hannu Krosing <hannu(at)skype(dot)net>
Cc: Douglas McNaught <doug(at)mcnaught(dot)org>, Mark Dilger <pgsql(at)markdilger(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PL/pgSQL 'i = i + 1' Syntax
Date: 2006-05-19 19:39:36
Message-ID: 20060519193936.GI64371@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, May 19, 2006 at 09:57:29PM +0300, Hannu Krosing wrote:
> ??hel kenal p??eval, R, 2006-05-19 kell 11:24, kirjutas Jim C. Nasby:
>
> > Something that's always bugged me is how horribly variables are handled
> > in plpgsql, namely that if you have a variable and a field with the same
> > name it can be extremely difficult to keep them seperated. Perhaps := vs
> > = might be a way to keep it clear as to which is which...
>
> I can't see how := helps here. Once you have fields, you are either in
> SQL-land and always use = or have the fields selected into a type or
> recors and can use record.field syntax.

The problem happens down in the SQL layer. Actually, I guess := wouldn't
help anything...

> > Though, a better way would probably just be to provide a built-in
> > construct for referencing plpgsql variables, such as $.
>
> Where is it exactly a problem which can't be solved simply by naming
> your variables differently from fields?

That's how I solve it, but a lot of newbies get bit by this. What makes
it really bad is that they typically get bit after they've already
written a bunch of code that doesn't prefix variable names with
something, so then they have to switch coding-conventions after they
already have a bunch of code written.

I think it would be better to at least strongly recommend always
prefixing variables and parameters with something. I'd argue that it'd
be even better to put us on the road of eventually mandating plpgsql
variables be prefixed with something (like $), but I'm not holding my
breath on that one...
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2006-05-19 19:54:32 Re: String Similarity
Previous Message Mark Woodward 2006-05-19 19:39:23 Re: [OT] MySQL is bad, but THIS bad?