pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
sequences in functions
3+ messages / 2 participants
[nested] [flat]

* sequences in functions
@ 2000-08-18 12:24  Graham Vickrage <graham@digitalplanit.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Graham Vickrage @ 2000-08-18 12:24 UTC (permalink / raw)
  To: pgsql-sql

I am having problems referencing sequeces in a function, I think because of
the '' characters. The function I am creating is a follows: -

CREATE FUNCTION InsertClient ( varchar, varchar, varchar, varchar, varchar,
varchar ) RETURNS int4 AS '
DECLARE
	id INT;
BEGIN
	SELECT nextval('client_seq') INTO id;

	INSERT INTO client (client_id, last_name, address1, country)
	VALUES (id, $1, $2, $3);

	INSERT INTO client_card (client_card_id, type, number, expiry_date,
client_id)
	VALUES (nextval('client_card_seq'), $4, $5, $6, id);

	RETURN id;
END;
' LANGUAGE 'plpgsql';


And the error message is

ERROR:  parser: parse error at or near "client_seq"
EOF


Is this because of the ' ' ???

Also can you pass in a array or hash to the function?

Cheers

Graham




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

* Re: sequences in functions
@ 2000-08-18 14:07  Yury Don <yura@vpcit.ru>
  parent: Graham Vickrage <graham@digitalplanit.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Yury Don @ 2000-08-18 14:07 UTC (permalink / raw)
  To: pgsql-sql

Hello Graham,

Friday, August 18, 2000, 6:24:15 PM, you wrote:

GV> I am having problems referencing sequeces in a function, I think because of
GV> the '' characters. The function I am creating is a follows: -

GV> CREATE FUNCTION InsertClient ( varchar, varchar, varchar, varchar, varchar,
GV> varchar ) RETURNS int4 AS '
GV> DECLARE
GV>         id INT;
GV> BEGIN
GV>         SELECT nextval('client_seq') INTO id;

GV>         INSERT INTO client (client_id, last_name, address1, country)
GV>         VALUES (id, $1, $2, $3);

GV>         INSERT INTO client_card (client_card_id, type, number, expiry_date,
GV> client_id)
GV>         VALUES (nextval('client_card_seq'), $4, $5, $6, id);

GV>         RETURN id;
GV> END;
GV> ' LANGUAGE 'plpgsql';


GV> And the error message is

GV> ERROR:  parser: parse error at or near "client_seq"
GV> EOF


GV> Is this because of the ' ' ???

You must to use two quotes:

SELECT nextval(''client_seq'') INTO id;

-- 
Best regards,
 Yury                            mailto:yura@vpcit.ru





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

* RE: sequences in functions
@ 2000-08-18 17:28  Graham Vickrage <graham@digitalplanit.com>
  parent: Yury Don <yura@vpcit.ru>
  0 siblings, 0 replies; 3+ messages in thread

From: Graham Vickrage @ 2000-08-18 17:28 UTC (permalink / raw)
  To: pgsql-sql

I have noticed that you can only pass 16 parameters to a function, I was
therefore wondering how you can do atomic inserts (such as the function
below but with more params) using pl/pgsql if you can't pass complex data
types. Is this something that transactions are not used for or is it best
done as two seperate calls in my perl scripts?

-----Original Message-----
From: pgsql-sql-owner@hub.org [mailto:pgsql-sql-owner@hub.org]On Behalf
Of Yury Don
Sent: 18 August 2000 15:07
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] sequences in functions


Hello Graham,

Friday, August 18, 2000, 6:24:15 PM, you wrote:

GV> I am having problems referencing sequeces in a function, I think because
of
GV> the '' characters. The function I am creating is a follows: -

GV> CREATE FUNCTION InsertClient ( varchar, varchar, varchar, varchar,
varchar,
GV> varchar ) RETURNS int4 AS '
GV> DECLARE
GV>         id INT;
GV> BEGIN
GV>         SELECT nextval('client_seq') INTO id;

GV>         INSERT INTO client (client_id, last_name, address1, country)
GV>         VALUES (id, $1, $2, $3);

GV>         INSERT INTO client_card (client_card_id, type, number,
expiry_date,
GV> client_id)
GV>         VALUES (nextval('client_card_seq'), $4, $5, $6, id);

GV>         RETURN id;
GV> END;
GV> ' LANGUAGE 'plpgsql';


GV> And the error message is

GV> ERROR:  parser: parse error at or near "client_seq"
GV> EOF


GV> Is this because of the ' ' ???

You must to use two quotes:

SELECT nextval(''client_seq'') INTO id;

--
Best regards,
 Yury                            mailto:yura@vpcit.ru





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


end of thread, other threads:[~2000-08-18 17:28 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-08-18 12:24 sequences in functions Graham Vickrage <graham@digitalplanit.com>
2000-08-18 14:07 ` Yury Don <yura@vpcit.ru>
2000-08-18 17:28   ` Graham Vickrage <graham@digitalplanit.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