Re: [ask] Return Query

From: Justin <justin(at)emproshunts(dot)com>
To: ataherster <ataherster(at)yahoo(dot)co(dot)id>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [ask] Return Query
Date: 2009-03-15 15:47:30
Message-ID: 49BD2312.80700@emproshunts.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

ataherster wrote:
> hai all, i'm trying create function like this
>
> CREATE OR REPLACE FUNCTION penjualan(idcb integer)
> RETURNS SETOF penjualan AS
>
>
> but this function is not work with this error : ERROR: structure of
> query does not match function result type
> CONTEXT: PL/pgSQL function "penjualan" line 6 at RETURN QUERY
>
> on the time i try with other table and working well
>
> thanks for your help
This is because Postgresql does know the structure of the data to be
returned. So the choice either use OUT command like so
http://www.postgresql.org/docs/current/static/plpgsql-declarations.html

Create or Replace Function penjualan(idcb, integer, OUT f1 text, OUT f2
integer) Returns SETOF penjualan AS

Or create a new data type describing the data structure
http://www.postgresql.org/docs/8.3/static/sql-createtype.html

Create Type myTable as ( f1 text, f2 integer)

Create or Replace Function penjualan(idcb, integer) Returns SETOF
myTable AS

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Carl Sopchak 2009-03-15 16:15:27 Re: ODBC limitation??
Previous Message Scott Marlowe 2009-03-15 14:11:15 Re: to_hex leading zeroes