public static void CloseCursorIfExists(this WorkspaceConnection ws, NpgsqlCommand cmd) { if (ws.Cursor != null && cmd.Any($"select 1 from pg_cursors where name = '{ws.Cursor}'")) { cmd.Execute($"close \"{ws.Cursor}\""); } }