Re: Re: Inserts in triggers Follow Up - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Re: Inserts in triggers Follow Up
Date
Msg-id web-91191@davinci.ethosmedia.com
Whole thread Raw
In response to Re: Inserts in triggers Follow Up  (Morgan Curley <mcurley@e4media.com>)
Responses Re: Re: Inserts in triggers Follow Up  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Morgan,

> One other problem I am having in that proc is SELECT'ing INTO a var.
>
> declare
>          id lookup_sports.sport_id%TYPE;
> begin
>          SELECT INTO id sport_id FROM lookup_sports WHERE....some
> clause
>
> id is always null

That's because the SELECT INTO variable and SELECT INTO record syntax
are confusingly different.  It's

for records:
SELECT INTO record_var * FROM ...

for simple variables:
SELECT column INTO variable FROM ...

I'm not clear on the origin of the inconsistency; my guess is that jan
copied it over from PL/SQL.

> good suggestion to differentiate my vars from my columns. For the
> sake of
> expediency I named them the same so when I was writing the insert
> statements I could just copy/past my columns list into my values
> list.

You should *always* do this.  Most functions with identical column and
variable names will confuse the compiler and result in errors.

It'd have been nice if PL/pgSQL supported variable naming with a special
character preifx (e.g. $variable).  Does anyone know of a character that
won't give the parser fits?  Currently I'm using "v_", same as Richard.

-Josh


______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

Attachment

pgsql-sql by date:

Previous
From: Renato De Giovanni
Date:
Subject: Meta integrity
Next
From: "Josh Berkus"
Date:
Subject: Re: Meta integrity