[postgis-users] Stored procedures
Arthur Bazin
arthurbazin at gmail.com
Wed Oct 18 11:53:12 PDT 2023
Hi,
That's pretty easy, take this DO :
DO
*$PROC$ DECLARE variable_1 text; BEGIN my function END$**PROC**$*
;
You can transform this into a procedure like this :
*CREATE PROCEDURE schema.function() AS*
*$**PROC*
*$ DECLARE my_var text; BEGIN my function END$**PROC**$*
*LANGUAGE PLPGSQL*
;
You can event add parameter into your procedure :
*CREATE PROCEDURE schema.function(my_var text) AS*
*$**PROC*
*$ DECLARE my_var2 text; BEGIN my function END$**PROC**$*
*LANGUAGE PLPGSQL*
;
The advantage is that you can reuse this function just by calling the
procedure, without rewriting the whole content.
So if you use your DO only one time, keep the DO.
If you expect to use it multiple times, then store it into a procedure.
To finish : function = return a value, procedure = do something without
returning anything but the two are very similar to write.
Have a nice day
Arthur Bazin
Le mar. 17 oct. 2023 à 17:53, Shaozhong SHI via postgis-users <
postgis-users at lists.osgeo.org> a écrit :
> How easily turn do statement scripts into stored procedures? Much
> modification is needed?
>
> What is the advantage to do so?
>
> Regards,
>
> David
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20231018/b7881bec/attachment.htm>
More information about the postgis-users
mailing list