Re: A "cascade on delete" constraints deletes AFTER the source is gone?? - Mailing list pgsql-general

From ON.KG
Subject Re: A "cascade on delete" constraints deletes AFTER the source is gone??
Date
Msg-id 19826044359.20041220163159@on.kg
Whole thread Raw
In response to Re: A "cascade on delete" constraints deletes AFTER the source is gone??  (Michael Fuhr <mike@fuhr.org>)
Responses Re: A "cascade on delete" constraints deletes AFTER the source is gone??  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
Hi All!

I need to make function which emulates table and returns setof columns
of this "table"

for example, i'm making query: "SELECT * FROM my_table(user_id)"

and function
CREATE OR REPLACE FUNCTION my_table (integer)
RETURNS setof text
AS '
  DECLARE
    check_date date;
    max_date date;
    r record;

  BEGIN
    max_date   := $2;
    check_date := $3;

    WHILE (check_date >= max_date) LOOP
      table_nam := ''table_''||to_char(check_date, ''YYYYMMDD'');

      FOR r IN EXECUTE ''SELECT COUNT(*) as cnt,
          AVG(amount) as avg_amount, SUM(amount) as sum_amount
        FROM ''||table_nam||''
        WHERE user_id = ''||$1||'' ''
      LOOP
        RETURN NEXT r.cnt || r.avg_amount || r.sum_amount;
      END LOOP;

      check_date := check_date - interval ''1 day'';
    END LOOP;

    RETURN;
  END;'
LANGUAGE 'plpgsql';


As a result i need to get a records, and will be able to use each
column from it

But my function doesn't work
What is wrong?

Thanx


pgsql-general by date:

Previous
From: Marco Colombo
Date:
Subject: Re: Scheduler in Postgres
Next
From: Együd Csaba
Date:
Subject: Re: PG8 final when