Single swaps of an array Inspired by Taken from a question at Stack Overflow.
The challenge
Given an integer n&gt;1, output all arrays that can be obtained by swapping exactly two entries in the array [1, 2, ..., n].
The arrays can be produced in any order.
You can consistently use [0, 1, ..., n-1] (0-based) instead of [1, 2, ..., n] (1-based).
Additional rules

Input and output are flexible as usual.

Programs or functions are allowed, in any programming language. Standard loopholes are forbidden.

Shortest code in bytes wins.


Test cases
Input 2 gives output (assumed 1-based)
2 1

Input 3 gives output (note that the three arrays could be in any order)
1 3 2
2 1 3
3 2 1

Input 4 gives output
1 2 4 3
1 3 2 4
1 4 3 2
2 1 3 4
3 2 1 4
4 2 3 1

Input 7 gives output
1 2 3 4 5 7 6
1 2 3 4 6 5 7
1 2 3 4 7 6 5
1 2 3 5 4 6 7
1 2 3 6 5 4 7
1 2 3 7 5 6 4
1 2 4 3 5 6 7
1 2 5 4 3 6 7
1 2 6 4 5 3 7
1 2 7 4 5 6 3
1 3 2 4 5 6 7
1 4 3 2 5 6 7
1 5 3 4 2 6 7
1 6 3 4 5 2 7
1 7 3 4 5 6 2
2 1 3 4 5 6 7
3 2 1 4 5 6 7
4 2 3 1 5 6 7
5 2 3 4 1 6 7
6 2 3 4 5 1 7
7 2 3 4 5 6 1
R, 54 bytes



function(n)combn(n,2,function(x){z=1:n
z[x]=rev(x)
z})


Try it online!

Returns a matrix where each column is a permutation.

combn(n,k) generates all combinations of size k from the list n, or from 1:n if n is a single integer. It also optionally takes a function FUN to be applied to the resultant combinations. So we write a function that performs the swap and returns the swapped list. The results are then all accumulated into an array, which is in this case 2-dimensional and hence a matrix.