Insert data to a log table
postgres=#
postgres=# create table logtable(t varchar(10), value varchar(10));
CREATE TABLE
postgres=#
postgres=#
postgres=# CREATE FUNCTION logfunc1(logtxt text) RETURNS timestamp AS $$
postgres$# BEGIN
postgres$# INSERT INTO logtable VALUES (logtxt, 'now');
postgres$# RETURN 'now';
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=#
postgres=# select logfunc1('text');
REATE
logfunc1
-------------------------
2006-10-21 15:16:38.375
(1 row)
postgres=#
postgres=# select * from logtable;
REATE
t | value
------+-------
text | now
(1 row)
postgres=#
postgres=# drop function logfunc1(logtxt text);
DROP FUNCTION
postgres=# drop table logtable;
DROP TABLE
postgres=#
postgres=#
Related examples in the same category