I\'m trying to delete all data related to a user id from a game database.
There is a table holding all games (each played by 3 players):
# select * f
You could create the temporary table and then do the usual INSERT ... SELECT as separate operations:
create temporary table temp_gids (gid int not null) on commit drop;
insert into temp_gids (gid) select gid from pref_scores where id = _id;
There's also a LIKE option to CREATE TABLE if you want to duplicate a table's structure:
LIKE parent_table [ like_option ... ]
TheLIKEclause specifies a table from which the new table automatically copies all column names, their data types, and their not-null constraints.
But I think you just need a temporary table to hold some IDs so that's probably overkill.
SELECT INTO works as you expect outside a procedure:
[...] this form of SELECT INTO is not available in ECPG or PL/pgSQL, because they interpret the INTO clause differently.
SELECT INTO is used to store the result of a SELECT in a local variable inside a PostgreSQL procedure:
The result of a SQL command yielding a single row (possibly of multiple columns) can be assigned to a record variable, row-type variable, or list of scalar variables. This is done by writing the base SQL command and adding an
INTOclause.