I must be blind...

From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: I must be blind...
Date: 2002-06-14 16:49:08
Message-ID: Pine.LNX.4.21.0206141739470.4131-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

'Afternoon folks,

I think I'm going blind I just can't spot what I've done wrong. Can someone
have a quick glance at this function, and relevent table definitions, and tell
me what I've got wrong please?

The error message I'm getting when I try to use it with:

SELECT new_transaction_fn(9, 444, 4, 'B', now(), 'C');

is:

NOTICE: Error occurred while executing PL/pgSQL function new_transaction_fn
NOTICE: line 11 at assignment
ERROR: parser: parse error at or near "SELECT"

(The select works and returns one row as I expect it to btw)

--
-- Tables
--

CREATE TABLE orders (
id INTEGER NOT NULL DEFAULT nextval('order_seq') PRIMARY KEY,
type INTEGER REFERENCES order_type(id),
instrument INTEGER REFERENCES instrument(id),
time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
market_price FLOAT8,
price FLOAT8,
quantity INTEGER,
direction CHAR(1) CHECK(direction = 'B' OR direction = 'S')
) WITHOUT OIDS;

CREATE TABLE transaction (
id INTEGER NOT NULL DEFAULT nextval('transaction_seq') PRIMARY KEY,
order_id INTEGER REFERENCES orders(id),
time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
price FLOAT8,
quantity INTEGER,
status CHAR(1) CHECK(status = 'c' OR status = 'C')
) WITHOUT OIDS;

--
-- Function
--

CREATE OR REPLACE FUNCTION new_transaction_fn (
integer,float8,integer,char(1),timestamp,char(1)
) RETURNS boolean AS '
DECLARE
ordid ALIAS FOR $1;
price ALIAS FOR $2;
quantity ALIAS FOR $3;
dirn ALIAS FOR $4;
time ALIAS FOR $5;
status ALIAS FOR $6;
BEGIN
-- check against order
PERFORM
SELECT 1
FROM orders
WHERE
id = ordid
AND
direction = dirn;
IF NOT FOUND THEN
RAISE EXCEPTION ''No order matching % / % found'', ordid, dirn;
END IF;

INSERT INTO transaction VALUES (
nextval(''transaction_seq''),
ordid,
COALESCE(time, now()),
price,
quantity,
COALESCE(status, ''C'')
);

RETURN TRUE;
END;
' LANGUAGE 'plpgsql';

--
--
--

Thanks,

--
Nigel J. Andrews
Director

---
Logictree Systems Limited
Computer Consultants

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Darren Ferguson 2002-06-14 17:09:23 Re: jobs.postgresql.org - Who's interested?
Previous Message Martijn van Oosterhout 2002-06-14 16:45:52 Re: Is md5 really more secure than crypt?

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-06-14 17:08:16 Breakage in crypt.c
Previous Message Josh Berkus 2002-06-14 16:32:03 Indexing for DESC sorts