Re: Fail of a return query from plpgsql function for a specific table

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Fail of a return query from plpgsql function for a specific table
Date: 2009-01-08 07:50:01
Message-ID: 20090108075001.GB15370@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

In response to c k :
> Hi all,
> I have a table accgroups and many others. I have written a test function as
> follows.
> CREATE OR REPLACE FUNCTION uf_testfunction()
> RETURNS SETOF associates AS
> $BODY$
> begin
> return query select * from associates;
> return;
> end;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
> This works fine for above table but not works at all for accgroups table. As I
> searched for this over web, it is identified as a bug for tables whose columns
> are changed(deleted and added). Is it true?
> How to solve this issue?
> Thanks
> CPK

I can't reproduce your problem:

test=# create table foo (a int, b int);
CREATE TABLE
test=# create or replace function get_foo() returns setof foo as $$begin return query select * from foo; return; end; $$ LANGUAGE 'plpgsql' VOLATILE;
CREATE FUNCTION
test=# select * from get_foo();
a | b
---+---
(0 rows)

test=# alter table foo add column c int;
ALTER TABLE
test=# select * from get_foo();
a | b | c
---+---+---
(0 rows)

(only if i drop a column):
test=# alter table foo drop column c;
ALTER TABLE
test=# select * from get_foo();
ERROR: structure of query does not match function result type
CONTEXT: PL/pgSQL function "get_foo" line 1 at RETURN QUERY

Please, provide us an example including the error you got.

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Gerd König 2009-01-09 10:32:48 suggestions/hints for multimaster solution
Previous Message Laszlo Nagy 2009-01-08 05:50:25 Re: rebellious pg stats collector (reopened case)

Browse pgsql-general by date

  From Date Subject
Next Message Reg Me Please 2009-01-08 07:51:03 Re: Error: column "host" does not exist
Previous Message SATYAJIT TRIPATHI 2009-01-08 07:41:03 Need help! To build geos-3.0.x lib using Sun Studio 12 compiler [conflict in file ConvexHull.cpp]