Re: Inserting a record returned from a function

From: "Guido Barosio" <gbarosio(at)gmail(dot)com>
To: p9e883002(at)sneakemail(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Inserting a record returned from a function
Date: 2008-04-16 13:55:36
Message-ID: f7f6b4c70804160655h68c28dber90e27dec591bc70f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

FYI your email account matched several spam engines

gb.-

On Wed, Apr 16, 2008 at 4:46 AM, <p9e883002(at)sneakemail(dot)com> wrote:
> I have a function defined as:
>
> CREATE OR REPLACE FUNCTION word_doc_from_raw(character varying, character
> varying, bytea)
> RETURNS record AS
> $BODY$
>
> SELECT ROW(
> id_from_word( $1 ),
> id_from_doc_name( $2 ),
> $3
> )
>
> $BODY$
> LANGUAGE 'sql' STABLE;
>
> And I'm trying to INSERT the returned record into a table defined as:
>
> CREATE TABLE word_doc
> (
> word_id integer NOT NULL,
> doc_id integer NOT NULL,
> posns bytea,
> CONSTRAINT word_doc_pkey PRIMARY KEY (word_id, doc_id),
> CONSTRAINT word_doc_word_id_fkey FOREIGN KEY (word_id)
> REFERENCES words (word_id) MATCH SIMPLE
> ON UPDATE RESTRICT ON DELETE RESTRICT
> )
> WITHOUT OIDS;
>
> with the statement:
>
> insert into word_doc ( word_id, doc_id, posns )
> values( (word_doc_from_raw( 'word', 'document.name', 'some raw data' )).* )
>
> and getting the error:
>
> ERROR: record type has not been registered
> SQL state: 42809
>
> Does this mean I must always define a type in order to do anything useful with a
> record returned from a function?
> I've seen references in the docs to "casting" and a syntax like:
>
> ROW( ...)::tag
>
> Is this useful in this situation?
>
> Cheers, buk.
>
>
>
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>

--
Guido Barosio
-----------------------
http://www.globant.com
guido(dot)barosio(at)globant(dot)com

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Nils Zierath 2008-04-16 17:05:51 Remote / network connection fails
Previous Message Sean Davis 2008-04-16 11:04:24 Re: Importing normalised data by SQL script in remote DB