psql - loop variable of loop over rows must be a record or row variable or list of scalar variables

PostgresqlPsql

Postgresql Problem Overview


Here is my simple anonymous code block:

do $$
  declare foo varchar(50) := '';
  begin
    for a in
      select a from (values('foo'), ('bar'), ('fooBar')) s(a)
    loop
      foo := a;
      print foo;
    end loop;
  end;
$$;

When I run it:

psql -f test.sql

I get this error:

psql:test.sql:11: ERROR:  loop variable of loop over rows must be a record or row variable or list of scalar variables
LINE 4:     for a in
            ^

Postgresql Solutions


Solution 1 - Postgresql

Solved it myself, meh. Needed to declare arow record.

do $$
  declare
    arow record;
    foo varchar(50);
  begin
    for arow in
      select a from (values('foo'), ('bar'), ('fooBar')) s(a)
    loop
      foo := arow.a;
      RAISE NOTICE 'Calling cs_create_job(%)', foo;
    end loop;
  end;
$$;

Solution 2 - Postgresql

How to retrieve the error Loop variable of loop over rows must be a record variable or list of scalar variables Line : For c_ rec IN (select datasourcenm,

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRichard KnopView Question on Stackoverflow
Solution 1 - PostgresqlRichard KnopView Answer on Stackoverflow
Solution 2 - Postgresqlrathna jayaramanView Answer on Stackoverflow