Re: Loading Array

From: Masaru Sugawara <rk73(at)sea(dot)plala(dot)or(dot)jp>
To: "Andrew Bartley" <abartley(at)evolvosystems(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Loading Array
Date: 2002-05-18 16:33:22
Message-ID: 20020518235856.6B95.RK73@sea.plala.or.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 17 May 2002 09:00:27 +1000
"Andrew Bartley" <abartley(at)evolvosystems(dot)com> wrote:

> insert into test
> select '''{' || concatkey || '}''' from visitor where user_id = 477373
>
> returns
>
> Error: ' but expression is of type 'text'
> You will need to rewrite or cast the expression (State:S1000, Native Code:
> 7)
>
> I'm sure I need to CAST the result... But to what type.. I have tried lots
> of different things but still carn't work it out.

Hi, Andrew.

No matter what type you cast the result to, it seems like there's no chance
that it can be inserted into array's column; actually, I couldn't either.
But, if using a dynamic query in plpgsql, you would be able to insert.

CREATE OR REPLACE FUNCTION fn_visitor (int4) RETURNS boolean AS '
DECLARE
sql text';
rec RECORD;
BEGIN
FOR rec IN SELECT * FROM visitor WHERE user_id = $1 LOOP
sql := ''insert into test values(''''{''
|| rec.concatkey
|| ''}'''');'';
EXECUTE sql;
RAISE NOTICE ''% is inserted.'', rec.concatkey;
END LOOP;
RETURN true;
END;
' language 'plpgsql' ;

SELECT fn_visitor(477373);

Regards,
Masaru Sugawara

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Doug Fields 2002-05-18 16:40:43 Re: Is there eny e-mail server that uses postgreSQL
Previous Message Wm. G. Urquhart 2002-05-18 14:07:13 More on "What am I doing wrong!"