[SQL] How to write cursors

2012-04-03 Thread La Chi
Hello everyone,

i have created this function in which i simply want to display a column values 
through a cursor , but unfortunately i am not getting the column values , this 
function is showing me simple column name but not the  fields in column.

CREATE OR REPLACE FUNCTION foo(id int) returns table(user_id int) as
$BODY$
DECLARE r int;
DECLARE rs cursor for Select userid from customer where area ='new_york';
BEGIN
open rs ;
fetch next from rs into r;
while (found) loop
fetch Next from rs into r;
END loop; 
close rs;  
END;
$BODY$
LANGUAGE plpgsql;


i simply want to show all the record from customer table where area is 
New York but with the help of cursors.
thanks

[SQL] Cursor Error

2012-04-03 Thread La Chi
Hello every one

i have created this function to test cursors , but when i execute this funtion 
it give me this error , how can i fix this error

CREATE OR REPLACE FUNCTION foo(custid int) returns table(userid int) as
$BODY$

DECLARE rs cursor for Select customer_name from customer;

BEGIN
fetch forward 5 in rs;
 
END;
$BODY$
LANGUAGE plpgsql;

error--

ERROR:  syntax error at or near ";"
LINE 7:  fetch forward 5 in rs;
                              ^

** Error **

ERROR: syntax error at or near ";"
SQL state: 42601
Character: 172


Re: [SQL] Wrong output from union

2012-04-03 Thread Jasen Betts
On 2012-04-02, Gary Stainburn  wrote:
> Thanks for this David.
>
> Does anyone know why it too until Saturday for my post to appear on the listr?
>
> Gary

If you haven't signed up for the mailing list with exactly the same email 
address that you post from the message will be held for moderation.

(standard weak antispam procedure)

-- 
⚂⚃ 100% natural


-- 
Sent via pgsql-sql mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] Duplicate information in parent and child tables

2012-04-03 Thread JORGE MALDONADO
I have a parent table and a child table. In order to detect duplicate
information I need to consider both tables. This means that a "duplicate
record" consists of one parent record and one or more child records.
Is there any standard approach to solve this issue?

Respectfully,
Jorge Maldonado


Re: [SQL] Duplicate information in parent and child tables

2012-04-03 Thread msi77
Maybe this will help http://sql-ex.ru/help/select18.php

04.04.2012, 02:03, "JORGE MALDONADO" :
> I have a parent table and a child table. In order to detect duplicate 
> information I need to consider both tables. This means that a "duplicate 
> record" consists of one parent record and one or more child records.  Is 
> there any standard approach to solve this issue?
>
> Respectfully,
> Jorge Maldonado

-- 
Sent via pgsql-sql mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql