pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Making a prepared statement in a stored procedure
2+ messages / 1 participants
[nested] [flat]

* Making a prepared statement in a stored procedure
@ 2004-12-28 17:12  Nathan Pickett <nathanpickett@hotmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Nathan Pickett @ 2004-12-28 17:12 UTC (permalink / raw)
  To: pgsql-sql; +Cc: nathanpickett@hotmail.com

Hi,

I am trying to convert the following function below:

---START FUNCTION
create or replace function 
update_tmp_sales_report_from_archive_with_prospects() returns integer as '
declare
    row_data record;
begin
    for row_data in select partner_id, count(*) as prospects from 
prospects_2004_09_01
    group by partner_id loop
        update tmp_sales_report_from_archive set prospects = 
row_data.prospects
        where partner_id = row_data.partner_id;
    end loop;

    return 1;
end;
' language 'plpgsql';
--- END FUNCTION

to be able to pass in the table named prospects_2004_09_01, to be prospects_ 
concatanated with the date, so prospects_2004_08_01, prospects_2004_07_01, 
etc.

I tried the following:

-- START TEST FUCTION
drop function update_tmp_sales_report_from_archive_with_prospects(text);
create or replace function 
update_tmp_sales_report_from_archive_with_prospects(text) returns integer as 
'
declare
    in_t ALIAS FOR $1;
    row_data record;
begin
    for row_data in select partner_id, count(*) as prospects in_t
    group by partner_id loop
        update tmp_sales_report_from_archive set prospects = 
row_data.prospects
        where partner_id = row_data.partner_id;
    end loop;

    return 1;
end;
' language 'plpgsql';
-- END TEST FUNCTION

but go the following errors:

DROP FUNCTION
CREATE FUNCTION
You are now connected as new user bp_sales_match_user.
psql:scratch.postgresql:36: WARNING:  Error occurred while executing 
PL/pgSQL function update_tmp_sales_report_from_archive_with_prospects
psql:scratch.postgresql:36: WARNING:  line 5 at for over select rows
psql:scratch.postgresql:36: ERROR:  parser: parse error at or near "$1" at 
character 44

Any suggestions?  Thanks! -Nate





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Making a prepared statement in a stored procedure
@ 2004-12-30 15:01  Nathan Pickett <nathanpickett@hotmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Nathan Pickett @ 2004-12-30 15:01 UTC (permalink / raw)
  To: pgsql-sql

Hi,

I am trying to convert the following function below:

---START FUNCTION
create or replace function 
update_tmp_sales_report_from_archive_with_prospects() returns integer as '
declare
row_data record;
begin
for row_data in select partner_id, count(*) as prospects from 
prospects_2004_09_01
group by partner_id loop
update tmp_sales_report_from_archive set prospects = row_data.prospects
where partner_id = row_data.partner_id;
end loop;

return 1;
end;
' language 'plpgsql';
--- END FUNCTION

to be able to pass in the table named prospects_2004_09_01, to be prospects_ 
concatanated with the date, so prospects_2004_08_01, prospects_2004_07_01, 
etc.

I tried the following:

-- START TEST FUCTION
drop function update_tmp_sales_report_from_archive_with_prospects(text);
create or replace function 
update_tmp_sales_report_from_archive_with_prospects(text) returns integer as 
'
declare
in_t ALIAS FOR $1;
row_data record;
begin
for row_data in select partner_id, count(*) as prospects in_t
group by partner_id loop
update tmp_sales_report_from_archive set prospects = row_data.prospects
where partner_id = row_data.partner_id;
end loop;

return 1;
end;
' language 'plpgsql';
-- END TEST FUNCTION

but go the following errors:

DROP FUNCTION
CREATE FUNCTION
You are now connected as new user bp_sales_match_user.
psql:scratch.postgresql:36: WARNING: Error occurred while executing PL/pgSQL 
function update_tmp_sales_report_from_archive_with_prospects
psql:scratch.postgresql:36: WARNING: line 5 at for over select rows
psql:scratch.postgresql:36: ERROR: parser: parse error at or near "$1" at 
character 44

Any suggestions? Thanks! -Nate





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-12-30 15:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-12-28 17:12 Making a prepared statement in a stored procedure Nathan Pickett <nathanpickett@hotmail.com>
2004-12-30 15:01 Making a prepared statement in a stored procedure Nathan Pickett <nathanpickett@hotmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox