I try this:
myvar := select "name" from "mytable" where "id" = 15;
But it causes an error. How can I assign the variable correctly?
It will work when you are using the INTO Keyword like
select "name" into myvar from "mytable" where "id" = 15;
But its possible that this returns more than one row. (Throws an Error in Oracle-SQL, cant speak for Postgres)
I think somithing like
select "name" into myvar from "mytable" where "id" = 15 limit 1;
would be better to fit your question title.
select "name" into myvar from "mytable" where "id" = 15;