Use CREATE TABLE AS
for that:
EXECUTE 'CREATE TABLE foo AS
SELECT name, work, phone
FROM info WHERE name = ' || quote_literal(in_name) || ' ORDER BY phone';
SELECT INTO
is discouraged for that purpose:
Combine two tables into a new one so that select rows from the other one are ignored
SELECT / EXECUTE .. INTO ..
is meant for single rows, not for whole tables in plpgsql.
And the assignment operator in plpgsql is :=
, not =
.
And a single quote was missing.
And don't use unquoted mixed case identifiers in Postgres.