I try to do this, but it's a syntax error, what am I doing wrong?
declare myid := insert into oameni values(default,'lol') returning id;
my table:
create table oameni
(
id serial primary key,
name varhcar(10)
);
I try to do this, but it's a syntax error, what am I doing wrong?
declare myid := insert into oameni values(default,'lol') returning id;
my table:
create table oameni
(
id serial primary key,
name varhcar(10)
);
You need to use the INTO clause in the RETURNING to set the value being returned into your variable:
DECLARE myid OAMENI.id%TYPE;
INSERT INTO oameni
VALUES
(default,'lol')
RETURNING id INTO myid;
You also need to specify the data type of your variable; I'm glad to see postgresql supports %TYPE and %ROWTYPE.