Unix Technical Forum

Small function in PLPGSQL

This is a discussion on Small function in PLPGSQL within the pgsql Novice forums, part of the PostgreSQL category; --> Hello, I'm learning plpsql and have a question: I would like to create a function that inserts a new ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:24 PM
Tirant Lo Blanc
 
Posts: n/a
Default Small function in PLPGSQL

Hello, I'm learning plpsql and have a question:

I would like to create a function that inserts a new record on my invoice table.
This table has an id (serial type).

I would like this function to return de id assigned to the new record.

any ideas?

Thanks, and excuse my poor English.



---------------------------------

Correo Yahoo!
Comprueba qué es nuevo, aquí
http://correo.yahoo.es
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:25 PM
Tjibbe Rijpma
 
Posts: n/a
Default Re: Small function in PLPGSQL

CREATE FUNCTION insert_row (VARCHAR, VARCHAR) RETURNS INT AS '
DECLARE
id INT;
BEGIN;
id := nextval('seq');
INSERT INTO table VALUES (id, $1, $2);
RETURN id;
END
LANGUAGE plpqsql;
----- Original Message -----
From: Tirant Lo Blanc
To: pgsql-novice@postgresql.org
Sent: Saturday, December 17, 2005 21:30
Subject: [NOVICE] Small function in PLPGSQL


Hello, I'm learning plpsql and have a question:

I would like to create a function that inserts a new record on my invoice table.
This table has an id (serial type).

I would like this function to return de id assigned to the new record.

any ideas?

Thanks, and excuse my poor English.



------------------------------------------------------------------------------

Correo Yahoo!
Comprueba qué es nuevo, aquí
http://correo.yahoo.es
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:24 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com