Re: [GENERAL] PostgreSQL sequence within function

2005-07-06 Thread Clark Allan
I figured it out... the problem was calling nextval("seq") with double quotes.   Normally, you would do "select nextval('seq')".  From within a function, calling nextval with single quotes around the argument, causes a syntax error.   SOLUTION: you need to use "backslash escape" sequences around th

Re: [GENERAL] PostgreSQL sequence within function

2005-07-06 Thread Clark Allan
Thanks for the help Tony, But im still having some trouble.   Here is the exact function --- CREATE OR REPLACE FUNCTION sp_slide_create(int4, bool, bool, bool, varchar, text, varchar, varchar, int4)RETURNS int4 AS'DECLARE aScriptID ALIAS FOR $1; aAllowDGP ALI

Re: [GENERAL] PostgreSQL sequence within function

2005-07-05 Thread Clark Allan
ahhh... very nice. Thank you. On 7/5/05, Tony Caduto <[EMAIL PROTECTED]> wrote: Or upgrade your server to 8.x and use dollar quoting.with dollar quoting all that is a thing of the past. CREATE FUNCTION sp_slide_create(int4) RETURNS int4 AS$$DECLAREaScriptID ALIAS FOR $1;seqID int4 := nextval('gense

Re: [GENERAL] PostgreSQL sequence within function

2005-07-05 Thread Tony Caduto
Or upgrade your server to 8.x and use dollar quoting. with dollar quoting all that is a thing of the past. CREATE FUNCTION sp_slide_create(int4) RETURNS int4 AS $$ DECLARE aScriptID ALIAS FOR $1; seqID int4 := nextval('genseq'); -- no magic needed with dollar qouting :-) BEGIN INSERT INTO tblsli

Re: [GENERAL] PostgreSQL sequence within function

2005-07-05 Thread Tony Caduto
Try this version of your function. I don't think you can assign a value to a variable in the declaration section with the return value of a function. CREATE OR REPLACE FUNCTION sp_slide_create(int4, bool, bool, bool, varchar, text, varchar, varchar, int4) RETURNS int4 AS' DECLARE aScriptID AL

Re: [GENERAL] PostgreSQL sequence within function

2005-07-01 Thread Tom Lane
Russ Brown <[EMAIL PROTECTED]> writes: > This just made me think. If I was writing this function, I would have > written it as an SQL function like this: > CREATE or REPLACE FUNCTION getSeq() RETURNS int AS $$ > SELECT nextval('myseq'); > $$ LANGUAGE SQL; > Does anybody know which version is actu

Re: [GENERAL] PostgreSQL sequence within function

2005-06-30 Thread Russ Brown
Tony Caduto wrote: > All you where really mising was a semi colon afer nextval('myseq') and > the begin end. > > CREATE or REPLACE FUNCTION getSeq() > RETURNS int AS > $$ > begin > RETURN nextval('myseq'); > end; > $$ > LANGUAGE 'plpgsql'; > > Clark Allan wrote: > This just made me think. If I

Re: [GENERAL] PostgreSQL sequence within function

2005-06-30 Thread Tony Caduto
All you where really mising was a semi colon afer nextval('myseq') and the begin end. CREATE or REPLACE FUNCTION getSeq() RETURNS int AS $$ begin RETURN nextval('myseq'); end; $$ LANGUAGE 'plpgsql'; Clark Allan wrote: -- CREATE FUNCTION getSeq() RET

[GENERAL] PostgreSQL sequence within function

2005-06-30 Thread Clark Allan
I am new to Postgre, and am still learning some of the basics... please bare with me. I need to know how to access a sequence from within a function. Let me know whats wrong with the following... (this is not the exact function, just for examples sake...) -