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

Поиск
Список
Период
Сортировка
От Jim C. Nasby
Тема Re: PL/pgSQL 'i = i + 1' Syntax
Дата
Msg-id 20060519193936.GI64371@pervasive.com
обсуждение исходный текст
Ответ на Re: PL/pgSQL 'i = i + 1' Syntax  (Hannu Krosing <hannu@skype.net>)
Ответы Re: PL/pgSQL 'i = i + 1' Syntax
Список 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@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Marc Munro
Дата:
Сообщение: Re: New feature proposal
Следующее
От: "Mark Woodward"
Дата:
Сообщение: String Similarity