Search Postgresql Archives

Re: writing a plpgsql query for the first time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

test=# create function testfunc()
test-# returns table (id int, code char(1)) as $$
test$#  BEGIN
test$#                  return query select id, code  from
record_table where id > 2;
test$#  END;
test$# $$ language plpgsql;

That's due to a clash in the identifiers' names. As you see you have an 'id' as output parameter, then 'id' in the query as part of the select and an 'id' as part of the WHERE condition.

I suggest that you change the query and specify directly the name of the fields, as follows:

return query select r.id, r.code from record_table r where r.id > 2;

Have a look on the documentation about this kind of issues, which has been improved from version 9 (http://www.postgresql.org/docs/9.0/interactive/plpgsql-implementation.html#PLPGSQL-VAR-SUBST).

Cheers,
Gabriele

--
 Gabriele Bartolini - 2ndQuadrant Italia
 PostgreSQL Training, Services and Support
 Gabriele.Bartolini@xxxxxxxxxxxxxx - www.2ndQuadrant.it

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux