Thread: record type
Hi. I need to know whether it's possible for a plpgsql function to accept record type parameters ? Is there a way to accomplishthat ?<br />I need to use something like ('1','2','3') as a parameter.<br /><br />regards<br />mk<br />
Or maybe anyone knows how to work with record types ? How to insert something like ('1','2','3') into a table, or split it? Anything ?<br /><br />regards<br />mk<br />
<br /><br /><div class="gmail_quote">2008/7/10 Marcin Krawczyk <<a href="http://jankes.mk">jankes.mk</a>@<a href="http://gmail.com">gmail.com</a>>:<br/><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204,204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hi. I need to know whether it's possible for a plpgsql functionto accept record type parameters ? Is there a way to accomplish that ?<br />I need to use something like ('1','2','3')as a parameter.<br /><br />regards<br /><font color="#888888">mk<br /></font></blockquote></div><br />All aboutrecord type<br /><a href="http://www.postgresql.org/docs/8.3/interactive/plpgsql-declarations.html#PLPGSQL-DECLARATION-RECORDS">http://www.postgresql.org/docs/8.3/interactive/plpgsql-declarations.html#PLPGSQL-DECLARATION-RECORDS</a><br />section 38.3.4<a name="PLPGSQL-DECLARATION-RECORDS"><br /><br /><br />but, try this ;-)<br /><br />merlin=# create tableyour_table(col1 int, col2 varchar(12), col3 int);<br />CREATE TABLE<br /><br />merlin=# create or replace function test_1(val_ofyour_table) returns void as $$<br /> declare<br />begin<br />insert into your_table values(val_of.col1, val_of.col2,val_of.col3);<br />end;<br />$$ LANGUAGE plpgsql;<br />CREATE FUNCTION<br /><br /><br />CREATE FUNCTION<br />merlin=#select test_1((1,'test',2));<br /> test_1<br /> --------<br /><br />(1 row)<br /><br /><br />merlin=# select *from your_table ;<br /> col1 | col2 | col3<br />------+------+------<br /> 1 | test | 2<br />(1 row)<br /><br />Time:0.380 ms<br /><br /><br /><br /></a><br />-- <br />--<br />Serdecznie pozdrawiam<br /><br />Pawel Socha<br /><a href="mailto:pawel.socha@gmail.com">pawel.socha@gmail.com</a><br/><br />programista/administrator<br /><br />perl -le 's**02).4^&-%2,).^9%4^!./4(%2^3,!#+7!2%^53%2&**y%&-;^[%"`-{ a%%s%%$_%ee'
Nice thanks a lot.
Niezłe, dzieki.
regards
pozdrowienia
mk
Niezłe, dzieki.
regards
pozdrowienia
mk
2008/7/11 Pawel Socha <pawel.socha@gmail.com>:
2008/7/10 Marcin Krawczyk <jankes.mk@gmail.com>:Hi. I need to know whether it's possible for a plpgsql function to accept record type parameters ? Is there a way to accomplish that ?
I need to use something like ('1','2','3') as a parameter.
regards
mk
All about record type
http://www.postgresql.org/docs/8.3/interactive/plpgsql-declarations.html#PLPGSQL-DECLARATION-RECORDS
section 38.3.4
but, try this ;-)
merlin=# create table your_table(col1 int, col2 varchar(12), col3 int);
CREATE TABLE
merlin=# create or replace function test_1(val_of your_table) returns void as $$
declare
begin
insert into your_table values(val_of.col1, val_of.col2, val_of.col3);
end;
$$ LANGUAGE plpgsql;
CREATE FUNCTION
CREATE FUNCTION
merlin=# select test_1((1,'test',2));
test_1
--------
(1 row)
merlin=# select * from your_table ;
col1 | col2 | col3
------+------+------
1 | test | 2
(1 row)
Time: 0.380 ms
--
--
Serdecznie pozdrawiam
Pawel Socha
pawel.socha@gmail.com
programista/administrator
perl -le 's**02).4^&-%2,).^9%4^!./4(%2^3,!#+7!2%^53%2&**y%& -;^[%"`-{ a%%s%%$_%ee'