Record unassigned yet

Поиск
Список
Период
Сортировка
Искать

Record unassigned yet

От:
"Johann Robette" <jrobette@onyme.com>
Дата:
Hello,

I'm experiencing a strange problem. Here it is :
I've created a function with a FOR loop.

DECLARE
Current RECORD;
BEGIN
FOR current IN SELECT * FROM employees LOOP	Tmp := current.id;
END LOOP;
...

When I call the function, I get the error :ERROR:  record " current " is unassigned yet

Any idea?



Re: Record unassigned yet

От:
Russell Smith <mr-russ@pws.com.au>
Дата:
On Fri, 1 Oct 2004 07:24 pm, Johann Robette wrote:
> Hello,
> 
> I'm experiencing a strange problem. Here it is :
> I've created a function with a FOR loop.
> 
> DECLARE
> Current RECORD;
> BEGIN
> FOR current IN SELECT * FROM employees LOOP
>   Tmp := current.id;
> END LOOP;
> ...
current != Current ?

> 
> When I call the function, I get the error :
>  ERROR:  record " current " is unassigned yet
> 
> Any idea?
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faqs/FAQ.html
> 
> 

RE : Record unassigned yet

От:
"Johann Robette" <jrobette@onyme.com>
Дата:
Oh sorry about that!
No, I was alright in the syntax. Both are defined as current.
I can't find where the problem lies...


-----Message d'origine-----
De : pgsql-hackers-owner@postgresql.org
[mailto:pgsql-hackers-owner@postgresql.org] De la part de Russell Smith
Envoyé : vendredi 1 octobre 2004 13:20
À : pgsql-hackers@postgresql.org
Objet : Re: [HACKERS] Record unassigned yet

On Fri, 1 Oct 2004 07:24 pm, Johann Robette wrote:
> Hello,
> 
> I'm experiencing a strange problem. Here it is :
> I've created a function with a FOR loop.
> 
> DECLARE
> Current RECORD;
> BEGIN
> FOR current IN SELECT * FROM employees LOOP
>   Tmp := current.id;
> END LOOP;
> ...
current != Current ?

> 
> When I call the function, I get the error :
>  ERROR:  record " current " is unassigned yet
> 
> Any idea?
> 
> 
> 
> ---------------------------(end of
broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faqs/FAQ.html
> 
> 

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if
your     joining column's datatypes do not match




Re: RE : Record unassigned yet

От:
Richard Huxton <dev@archonet.com>
Дата:
Johann Robette wrote:
> Oh sorry about that!
> No, I was alright in the syntax. Both are defined as current.
> I can't find where the problem lies...

The following works fine for me.

=== BEGIN test ===
DROP TABLE employees;

CREATE TABLE employees (id integer, name text);
COPY employees FROM stdin;
1   Aaron Aardvark
2   Betty Bee
3   Carl Cat
\.

CREATE OR REPLACE FUNCTION emp_test_fn() RETURNS boolean AS '
DECLARE    current RECORD;    Tmp     integer;
BEGIN    FOR current IN SELECT * FROM employees LOOP        Tmp := current.id;        RAISE NOTICE ''tmp = %'', Tmp;    END LOOP;    RETURN true;
END
'
LANGUAGE 'plpgsql';

SELECT emp_test_fn();
=== END test ===

PS - please reply to the -general list not -hackers.

--   Richard Huxton  Archonet Ltd

Re: Record unassigned yet

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Johann Robette"  writes:
> I've created a function with a FOR loop.

> DECLARE
> Current RECORD;
> BEGIN
> FOR current IN SELECT * FROM employees LOOP
> 		Tmp := current.id;
> END LOOP;
> ...

> When I call the function, I get the error :
> 	ERROR:  record " current " is unassigned yet

> Any idea?

What you showed us looks fine, therefore the problem is in something you
didn't show us.
		regards, tom lane

RE : Record unassigned yet

От:
"Johann Robette" <jrobette@onyme.com>
Дата:
Thanks for your answer.
In fact, I had a syntax error in my function.
Sorry about that!

-----Message d'origine-----
De : Tom Lane [mailto:tgl@sss.pgh.pa.us] 
Envoyé : vendredi 1 octobre 2004 16:47
À : Johann Robette
Cc : pgsql-hackers@postgresql.org
Objet : Re: [HACKERS] Record unassigned yet 

"Johann Robette"  writes:
> I've created a function with a FOR loop.

> DECLARE
> Current RECORD;
> BEGIN
> FOR current IN SELECT * FROM employees LOOP
> 		Tmp := current.id;
> END LOOP;
> ...

> When I call the function, I get the error :
> 	ERROR:  record " current " is unassigned yet

> Any idea?

What you showed us looks fine, therefore the problem is in something you
didn't show us.
		regards, tom lane



FAQ