Hi there, i'm new to postgres. I want to create view when adding new row. So what i've got:
CREATE OR REPLACE FUNCTION add_view() RETURNS trigger AS $$
DECLARE
someint integer;
BEGIN
RAISE NOTICE 'dodajesz nowa lige %', NEW.id;
someint := NEW.id;
RAISE NOTICE 'dodajesz nowa lige %', someint;
CREATE VIEW tabelka AS SELECT * FROM t_matches.someint;
RETURN NULL;
END;
$$ language plpgsql;
CREATE TRIGGER league AFTER insert ON t_leagues FOR STATEMENT EXECUTE PROCEDURE add_view();
Then in psql I made an query and got error:
league=# INSERT INTO t_leagues (name) VALUES('3liga');
ERROR: record "new" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: PL/pgSQL function "add_view" line 4 at RAISE
Whats wrong, I supposed that id is not reserverd at the moment, so what can I do?
And here is some infos about table
league=# \d t_leagues
Table "public.t_leagues"
Column | Type | Modifiers
------------+-----------------------+--------------------------------------------------------
id | integer | not null default nextval('t_leagues_id_seq'::regclass)
name | character varying(20) | not null
data_start | date |
data_end | date |
awans | smallint | not null default 0
baraz | smallint | not null default 0
spadek | smallint | not null default 0
Indexes:
"t_leagues_pkey" PRIMARY KEY, btree (id)
Triggers:
league AFTER INSERT ON t_leagues FOR EACH STATEMENT EXECUTE PROCEDURE add_view()