| From: | Perry Smith <pedzsan(at)gmail(dot)com> | 
|---|---|
| To: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Cursor Example Needed | 
| Date: | 2013-10-28 21:06:30 | 
| Message-ID: | 194640B3-4F22-47C4-8E38-7DCCEF958EAD@gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
When I execute the SELECT statement directly I get:
psql:table.sql:28: out of memory for query result
I've read the way around this is to use cursors. So I read and I see that I can use a FOR statement but I need that inside a function.
So far, I've come up with this:
> CREATE OR REPLACE FUNCTION blah() RETURNS integer AS $$
> 
> DECLARE
>   xyz CURSOR FOR SELECT * FROM shipped_files WHERE aix_file = '/usr/lib/drivers/vioentdd' AND service_pack = '7100-01-06';
> 
> BEGIN
>   FOR my_rec IN xyz LOOP
>     -- xyxyxy what to do where? xyxyxy  These things don't work:
>     COPY ( my_rec ) TO stdout;
>     SELECT * FROM my_rec;
>     etc.
>   END LOOP;
> 
>   RETURN 5;
> END
> $$ LANGUAGE plpgsql;
> 
> SELECT * FROM blah();
I just want to output the rows being selected as text. Basically I want the same output that the SELECT statement would produce if it didn't fail.
Also, what should I do with the SELECT * FROM blah() statement? I'm doing that just to get blah() to execute. I have a feeling I'm way far off base.
Thank you,
Perry
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Herouth Maoz | 2013-10-28 21:07:19 | Re: Table partitioning | 
| Previous Message | Steve Crawford | 2013-10-28 20:31:33 | Re: Table partitioning |