Subject: PL/PgSQL INTO (used to be BUG #8870)

From: Marko Tiikkaja <[email-masked]>
Date: Thu, 31 Jul 2014 23:34:35 +0200

Hi,

As discussed in #8870, the docs make unfounded claims on INTO.  Here's a 
patch removing the incorrect part.

.marko
*** a/doc/src/sgml/plpgsql.sgml
--- b/doc/src/sgml/plpgsql.sgml
***************
*** 1023,1032 **** DELETE ... RETURNING <replaceable>expressions</replaceable> INTO <optional>STRIC
     </tip>
  
      <para>
!      If a row or a variable list is used as target, the query's result columns
!      must exactly match the structure of the target as to number and data
!      types, or else a run-time error
!      occurs.  When a record variable is the target, it automatically
       configures itself to the row type of the query result columns.
      </para>
  
--- 1023,1029 ----
     </tip>
  
      <para>
!      When a record variable is the target, it automatically
       configures itself to the row type of the query result columns.
      </para>

-- 
Sent via pgsql-docs mailing list ([email-masked])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs

---

From: Marti Raudsepp <[email-masked]>
Date: Fri, 1 Aug 2014 14:33:28 +0300

On Fri, Aug 1, 2014 at 12:34 AM, Marko Tiikkaja <[email-masked]> wrote:
> Here's a patch removing the incorrect part.

I can see how this doc statement can be misunderstood, but I think the
claims are actually about data types, not the number of columns in the
INTO list.

I think clarifying the number of columns quirk would be better than
removing this text.

Regards,
Marti

---

From: Marko Tiikkaja <[email-masked]>
Date: Fri, 01 Aug 2014 13:43:44 +0200

> claims are actually about data types, not the number of columns in the

I don't really speak English, but I can't see what else the "as to 
number" part could mean.

But the claim about "exactly matching" data types is completely bogus, too:

   local:marko=#* do $$ declare _f1 timestamp;
   local:marko$#* begin select current_date into _f1;
   local:marko$#* end $$ ;
   DO

   local:marko=# do $$ declare _f1 timestamp;
   local:marko$# begin select text '2004-01-01' into _f1;
   local:marko$# end $$ ;
   DO

.marko

---

From: Marti Raudsepp <[email-masked]>
Date: Fri, 1 Aug 2014 15:57:10 +0300

On Fri, Aug 1, 2014 at 2:43 PM, Marko Tiikkaja <[email-masked]> wrote:
> But the claim about "exactly matching" data types is completely bogus, too

My bad. I remember having a hard time with matching data types in
PL/pgSQL in one instance, but turns out that was with RETURN QUERY,
not INTO.

Anyway, I'd prefer adding an explicit warning about the non-strict
behavior. How about:

"The number of columns returned by the query is not checked to match
target variables. Superfluous target variables are assigned the value
NULL.
When a record variable is the target, it automatically
configures itself to the row type of the query result columns."

Regards,
Marti