Problem with ALIAS? - Mailing list pgsql-novice
From | Keith Worthington |
---|---|
Subject | Problem with ALIAS? |
Date | |
Msg-id | 20041222055457.M70638@narrowpathinc.com Whole thread Raw |
Responses |
Re: Problem with ALIAS?
|
List | pgsql-novice |
Hi All, I am working on the function below. whenever I run it I get the following: IPADB=# SELECT inventory.commit_scanner_data('monthly', 'this_is_a_test'); WARNING: Error occurred while executing PL/pgSQL function commit_scanner_data WARNING: line 9 at SQL statement ERROR: parser: parse error at or near "$1" at character 150 IPADB=# I have kicked this thing around a half dozen times and can't seem to find my mistake. What am I doing wrong? CREATE OR REPLACE FUNCTION inventory.commit_scanner_data(TEXT, TEXT) RETURNS INTEGER AS ' DECLARE v_inventory_date DATE; rcrd_item RECORD; rcrd_scanner RECORD; v_inventory_type ALIAS FOR $1; v_note ALIAS FOR $2; BEGIN -- Retrieve the minimum date to use as the inventory date. SELECT CAST(extract(year from min(scan_timestamp)) || extract(month from min(scan_timestamp)) || extract(day from min(scan_timestamp)) AS date) AS v_inventory_date FROM inventory.tbl_scanner; -- Insert the detail information into the detail table. INSERT INTO inventory.tbl_detail ( inventory_date, inventory_type, note ) VALUES ( v_inventory_date, v_inventory_type, v_note ); -- Loop through the item ids. FOR rcrd_item IN SELECT inventory.tbl_scanner.item_id, sum( inventory.tbl_scanner.quantity ) AS total FROM inventory.tbl_scanner GROUP BY inventory.tbl_scanner.item_id ORDER BY inventory.tbl_scanner.item_id LOOP -- Insert the current record into the target table. INSERT INTO inventory.tbl_data ( inventory_id, item_id, quantity ) VALUES ( currval(''inventory.tbl_detail_inventory_id_seq''::text), rcrd_item.item_id, rcrd_item.total ); -- Insert the original scanner data into the archive table. FOR rcrd_scanner IN SELECT inventory.tbl_scanner.scan_timestamp, inventory.tbl_scanner.item_id, inventory.tbl_scanner.quantity, inventory.tbl_scanner.employee_id, inventory.tbl_scanner.void FROM inventory.tbl_scanner WHERE inventory.tbl_scanner.item_id = rcrd_item.item_id LOOP -- Insert the current record into the target table. INSERT INTO inventory.tbl_archive ( inventory_id, scan_timestamp, item_id, quantity, employee_id, void ) VALUES ( currval(''inventory.tbl_detail_inventory_id_seq''::text), rcrd_scanner.scan_timestamp, rcrd_scanner.item_id, rcrd_scanner.quantity, rcrd_scanner.employee_id, rcrd_scanner.void ); END LOOP; -- The record has been processed. Remove it from the scanner table. DELETE FROM inventory.tbl_scanner WHERE inventory.tbl_scanner.item_id = rcrd_item.item_id; END LOOP; RETURN 1; END; ' LANGUAGE 'plpgsql'; Kind Regards, Keith ______________________________________________ 99main Internet Services http://www.99main.com
pgsql-novice by date: